We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Set Output tray/Bin

Hi Support,

I want to set output tray/bin (not paper source) while printing. I found out that PDFNEWNET-35708 is about same requirement.

Can you please suggest how to achieve this?

@shripadbhat

Thank you for contacting support.

You can use System.Drawing.Printing.PageSettings class of .NET framework and specify PaperSource property as per your requirements. Then you can pass printer and page settings to PrintDocumentWithSettings method of PdfViewer class. Below is a code snippet for your kind reference.

Document doc = new Document("Test.pdf");
PdfViewer viewer = new PdfViewer();
viewer.BindPdf(doc);
viewer.PrinterJobName = System.IO.Path.GetFileName(doc.FileName);
viewer.Resolution = 110;
// Set attributes for printing
viewer.AutoResize = true; // Print the file with adjusted size
viewer.AutoRotate = false; // Print the file with adjusted rotation
viewer.PrintPageDialog = false; // Do not produce the page number dialog when printing
viewer.RenderingOptions.UseNewImagingEngine = true;
// 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();
// Set printer name
ps.PrinterName = "Microsoft Print to PDF";
pgs.PaperSize = new System.Drawing.Printing.PaperSize(paperTypeName, paperWidth, paperHeight);
pgs.Margins = new System.Drawing.Printing.Margins(margins.Left, margins.Right, margins.Top, margins.Bottom);
pgs.PaperSource =  GetPaperSource(printerName, trayName);
// Print document using printer and page settings
viewer.PrintDocumentWithSettings(pgs, ps);

We hope this will be helpful. In case you face any problem related with Aspose.PDF for .NET API then please share details with us.

what code does GetPaperSoruce(printerName, tryaName); use to get the paper sources. I do not see this function inside this code block. Am I missing it?

Thanks,
John

I am also not aware of where this code picks up trayname. How is the trayname determined.

@jwquinn

Below is the code for GetPaperSoruce method where you pass name of the tray as string.

        /// <summary>
        /// Return the PaperSource object for the provided printer and tray name.
        /// </summary>
        /// <param name="printerName"></param>
        /// <param name="trayName"></param>
        /// <returns></returns>
        public static System.Drawing.Printing.PaperSource GetPaperSource(string printerName, string trayName)
        {
            System.Drawing.Printing.PaperSource ps = null;
            System.Drawing.Printing.PrintDocument prtDoc = new System.Drawing.Printing.PrintDocument();
            prtDoc.PrinterSettings.PrinterName = printerName;
            for (int i = 0; i < prtDoc.PrinterSettings.PaperSources.Count; i++)
            {
                if (prtDoc.PrinterSettings.PaperSources[i].SourceName.ToLower().Equals(trayName.ToLower()))
                {
                    ps = prtDoc.PrinterSettings.PaperSources[i];
                    break;
                }
            }
            return ps;
        }

Please feel free to contact us if you need any further assistance.