Different pages in a document to different paper trays on a printer

How to print different pages in a document to different paper trays on a printer?

I need to print the first page of a document to one paper tray, the last page to another paper tray and the pages between to a third paper tray.

Hi Knut,

You can print the PDF pages to different paper trays using a combination of PdfViewer, PageSettings and your custom coding.

First of all, please have a look at this topic. It helps you understand how to use PrinterSettings and PageSettings classes of System.Drawing.Printing namespace. You can use PageSettings class to set PaperSource (the paper tray). You can also set FromPage and ToPage properties to set the starting and ending page to be printed in this particular paper source.

Now, if you want to print different pages to different paper sources, you’ll have to send a print for each set of pages with particular paper source and from page and to page settings separately.

For example, first send page range 1 - 1 to printer tray one and then page range 2 - 10 to printer tray two and so on for as many sets of pages and paper trays as you like.

I hope this helps. If you have any further questions, please do let us know.
Regards,

I have made a test application in C# where I can choose a paper source and print to it, so I am pretty sure that I have the right paper source.
Here are my code where I try to do the printing.
Can you tall me where I go wrong?

viewer.OpenPdfFile(pdfFile);
viewer.AutoResize = true; //print the file with adjusted size
viewer.AutoRotate = true; //print the file with adjusted rotation
viewer.PrintPageDialog = false; //do not produce the page number dialog when printing
System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();
System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();
System.Drawing.Printing.PrintDocument prtdoc = new System.Drawing.Printing.PrintDocument();
ps.PrinterName = prtdoc.PrinterSettings.PrinterName;
pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
ps.FromPage = 1;
ps.ToPage = 1;
ps.PrintRange = PrintRange.SomePages;
foreach (PaperSource pasu in pgs.PrinterSettings.PaperSources)
{
if (pasu.SourceName.Trim() == myPrinter.PaperTrayPage1.Trim())
{
pgs.PaperSource = pasu;
}
}
viewer.PrintDocumentWithSettings(pgs, ps);
ps.FromPage = 2;
ps.ToPage = ps.MaximumPage;
ps.PrintRange = PrintRange.SomePages;
foreach (PaperSource pasu in pgs.PrinterSettings.PaperSources)
{
if (pasu.SourceName.Trim() == myPrinter.PaperTrayRest.Trim())
{
pgs.PaperSource = pasu;
}
}
viewer.PrintDocumentWithSettings(pgs, ps);
viewer.ClosePdfFile();

Hi Knut,

Could you please share what problem you’re facing at your end using above code snippet? Are pages not printing or printing from the wrong tray? Please share the situation with us, so we could further look into it at our end.

We’re sorry for the inconvenience.
Regards,

The pages are printing, but not from the right tray. It seems that they all come from the same tray.

As I described earlier, I have made a test application that prints from different paper sources, so I am pretty sure that I have defined the right tray. I have also stepped through the code, so I have confirmed that I have a match for the tray defined.

Hi Knut,

Thank you for sharing further details. We’ll investigate this issue in detail and update you the earliest possible.

We’re sorry for the inconvenience.
Regards,

It seems that I have found a solution to this problem.

I have to iterate trough the PrinterSettings instead of the PageSettings like this:

foreach (PaperSource pasu in ps.PaperSources)

{

if (pasu.SourceName.Trim() == myPrinter.PaperTrayPage1.Trim())

{

pgs.PaperSource = pasu;

}

}

Hi Knut,

I’m glad to know that this issue is resolved. Thank you very much for sharing the hint with us. This might help other users as well.

Regards,