In C#, I have a collection of BitmapSource that are in the same document. These BitmapSources have independent page orientation each, and I want to print them, keeping the page orientation set for each page, in the same print job.
Today, I'm unable to do it, since I'm using PrintDialog class, and each BitmapSource is added to a FixedPage, inside a FixedDocument - with this approach, I can only set the page orientation to the whole document (one orientation per print ticket). What should I do to print several BitmapSources with different page orientations in a single print job (in the PrintDialog class, using only one print ticket)?
I can't leave comments yet since I only have 11 rep, but I'll try to give your the information I have which might help.
A couple things: it may depend on how you're creating the
FixedDocument
and generatingFixedPage
s. If you're first generating aFixedPage
and then adding it to aFixedDocument
, I can think of one thing you can try.Also, it depends on how you're printing the pages, are printing each page or do you want to call print once, and print the entire document.
Anyways, one way to do it is to adjust the sizes of the fixed pages before you add them to the document. If you use the print dialog, take the print ticket properties and scale your controls or what have you, to the size they need to be.
This worked for me:
And tmp.xps in Windows Explorer preview looks like:
Let's say you don't want to print it to a file, or you want to send it to a printer as well.
Note: The print out will only have correct orientation if you print using a XPS device. See
PrintQueue.IsXpsDevice
If this doesn't suit your needs, you will have to write your own
DocumentPaginator
which allows you to handle printing for each page. One option you have here is to transform your visuals/pages as they are called inDocumentPaginator.GetPage(int index)
. Remember to call Measure, Arrange, and UpdateLayout for each page if you change any UI properties.