I want to print multiple pdf document in different tray in single click.
e.g. i have a button in UI and when user click that button i want to print two pdf document on different tray.
string[] files = null;
files = Directory.GetFiles("D:\\files", "*.pdf");
foreach (string lcFile in files)
{
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(lcFile);
PrinterSettings.PaperSourceCollection collections = doc.PrintDocument.PrinterSettings.PaperSources;
List<PdfPaperSourceTray> loPaperSources = new List<PdfPaperSourceTray>();
//Assume collections[2] is big A3,and collections[3] is A4.
PdfPageBase loPage = doc.Pages[0];
if (loPage.Size == PdfPageSize.A4)
{
PdfPaperSourceTray tray = new PdfPaperSourceTray();
tray.StartPage = 0;
tray.EndPage = doc.Pages.Count - 1;
tray.PrintPaperSource = collections[3];
loPaperSources.Add(tray);
}
else //A3
{
PdfPaperSourceTray tray = new PdfPaperSourceTray();
tray.StartPage = 0;
tray.EndPage = doc.Pages.Count - 1;
tray.PrintPaperSource = collections[2];
loPaperSources.Add(tray);
}
doc.PageSettings.ListPaperSourceTray = loPaperSources;
doc.PrintDocument.Print();
}