There is no need to create a hidden window, you can display WPF controls for printing using DocumentPage . To print a DocumentPage , you will need to extend the DocumentPaginator class.
Below is the code for implementing a simple DocumentPaginator that will output any List from UIElements .
class DocumentPaginatorImpl : DocumentPaginator { private List<UIElement> Pages { get; set; } public DocumentPaginatorImpl(List<UIElement> pages) { Pages = pages; } public override DocumentPage GetPage(int pageNumber) { return new DocumentPage(Pages[pageNumber]); } public override bool IsPageCountValid { get { return true; } } public override int PageCount { get { return Pages.Count; } } public override System.Windows.Size PageSize { get { if (Pages.Count > 0) { UIElement page = Pages[0]; if (page is Canvas) return new Size(((Canvas)page).Width, ((Canvas)page).Height);
Finally, in order to print, you will need:
dialog.PrintDocument(new DocumentPaginatorImpl(pages), "Print Job Description");
source share