views:

53

answers:

2

I'm trying to print a WPF canvas over multiple pages.

I'm perfectly happy with scaling it to fit on the page width, then clipping and translating the canvas for each page; all pretty simple maths.

What I don't understand is how I get the dimensions of the printable area, and how to tell the printer where to print to. Whatever I try it appears the values I'm using are the size of the paper, and i therefore get cropping occurring as the printer cant print right to the edge of the paper.

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

capabilities has the following properties:

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

What is the "imageable" area? is that the area on the paper in which I can put content? I guess 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 do I find this information?

What should the PageSize property of the DocumentPaginator be set to? Should I set this from capabilities.PageImageableArea? Or does the dialog.Print() function set this, and i just need to read from it in GetPage()?

Finally, when I return a DocumentPage, what do I pass to the three geometry arguments pageSize, bleedBox and contentBox?

Thanks :)

+1  A: 

Have you looked at using a FlowDocument instead of just printing the Canvas? there is a good example of creating and printing Here.

Hopefully that would negate the need for a lot of the Math.

Blounty
how do i get a flowdocument from a canvas?
Andrew Bullock
forget trying to print the canvas and create a FlowDocument to Bind your Data to. esentially Recreate what is in your canvas in a FlowDocument.
Blounty
A: 

Ok it seems that printing always occurs from (0, 0) (top left) of the paper.

Get the size of the paper with:

printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight

and the top and left margins with:

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

I assumed that the bottom and right margins were the same as the top and left, although this may not be safe.

You have to scale and clip the canvas as you normally would, then apply a TranslateTransform the size of your margins to move the content in to the printable area.

Andrew Bullock