I have been looking around for a solution to print to a non default printer and have the ability to specify the tray. How can this be done? I have seen that you would use PrinterSettings from the Drawing namespace, but how is the papersource (Tray) set?
Hi,
Thank you for considering Aspose.Pdf.
You can specify the printer name using PrinterName property of System.Drawing.Printing.PrinterSettings class. Regarding setting the paper tray, you can use PaperSource property of System.Drawing.Printing.PageSettings class. Please see the following documentation link for details and sample code regarding PDF document printing using Aspose.Pdf for .NET.
Printing PDF to an XPS Printer (Facades)
Please feel free to contact support in case you need any further assistance.
Thank You & Best Regards,
Yes, I did see this, do you have an example with printing to a Tray?
Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Following is my code which I use to set the printer tray.
//create PdfViewer object
PdfViewer viewer = new PdfViewer();
//open input PDF file
viewer.BindPdf(@"D:\AP Data\September2012\image.pdf");
//set attributes for printing
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
//create objects for printer and page settings and PrintDocument
System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();
System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();
//specify your printer name
ps.PrinterName = myPrinterName;
//set PageSize (if required)
pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);
//set PageMargins (if required)
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
//Here you can set the PaperSource which you want to use as per your printer.
pgs.PaperSource = ps.PaperSources[1];
//print document using printer and page settings
viewer.PrintDocumentWithSettings(pgs, ps);
//close the PDF file after priting
viewer.Close();
The
problem I am having is that when I try to set the PaperSources it fails because
the PrinterSettings.PaperSources collection is empty.
Well, it seems to be a printer specific issue (as System.Drawing.Printing.PrinterSettings is not Aspose.Pdf class but a .NET class to get installed printers settings on a system). As per my testing, I can see all the PaperSources as per the above code (in bold) according to my printer. Please share your printer details and printer preferences with us so we can see if we can figure our something from those details.
Sorry for the inconvenience,