In my WPF application I want to print a custom generated FlowDocument but I have big problems getting the pages on the center of the paper. Every page is aligned to the upper left corner. Even so close the printer can not reach it. Small parts of the document are missing. On the lower and right side there is plenty of empty space so the document can easiely fit on the paper. If it would be centered!
Is the any way to set borders/margin/or offset for the PrintTicket or the Paginator?
I did not find anything that would work.
This is what I do:
// selectedDocument is a FlowDocument
private const double PAGE_HEIGHT = 728;
private const double PAGE_WIDTH = 1024;
var paginator
= ((IDocumentPaginatorSource)this .selectedDocument).DocumentPaginator;
paginator.PageSize = new Size(PAGE_WIDTH, PAGE_HEIGHT);
printDialog.PrintTicket.PageOrientation
= System.Printing.PageOrientation.Landscape;
printDialog.PrintDocument(paginator, "Report");
I also tried different page sizes but it makes no difference.
If I save my FlowDocument as XpsDocument via XpsSerializationManager the created file looks perfect. Borders and margins are all as they should be. In a later step I use this file to create a pdf file. If I then print the pdf-File it looks fine on paper too.