WPF DocumentPaginator and DocumentPage unexpected cropping

I am trying to print a WPF canvas on multiple pages.

I am very pleased with scaling it to fit the page, and then clipping and translating the canvas for each page; all pretty simple maths.

What I don’t understand is how I get the size of the printable area and how to tell the printer where to print. No matter what I try to do, the values ​​I use are the paper size, and therefore I get cropping when the printer cannot print on the edge of the sheet.

var capabilities = printDialog.GetPrintCapabilities(dialog.PrintTicket); 

possesses the following properties:

 capabilities.PageImageableArea.ExtentWidth // "Gets the width of the imageable area" 

What is the area of ​​the image? Is this an area on paper where I can post content? I think so because:

 capabilities.PageImageableArea.OriginWidth // Gets the distance from the left edge of the page to the imageable area. 

However, what about the bottom and right margins? Where can I find this information?

What should the PageSize property be set for the DocumentPaginator parameter? Should I install this from capabilities.PageImageableArea ? Or dialog.Print() function set this value and I just need to read it in GetPage() ?

Finally, when I return a DocumentPage , what do I pass the third arguments to the PageSize , bleedBox and contentBox ?

Thanks:)

+4
source share
2 answers

It seems good that printing always comes from (0, 0) (top left) from paper.

Get the paper size using:

 printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight 

and the top and left margins:

 var printCapabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket); printCapabilities.PageImageableArea.OriginWidth, printCapabilities.PageImageableArea.OriginHeight 

I assumed that the lower and right margins are the same as the upper and left margins, although this may be unsafe.

You must scale and crop the canvas as usual, and then apply the TranslateTransform size of your margins to move the content to the printable area. A.

+4
source

Have you considered using FlowDocument instead of just printing Canvas? There is a good example of creating and printing here .

Hopefully this would deny the need for a significant part of the math.

+1
source

Source: https://habr.com/ru/post/1314943/


All Articles