ASP.NET Printing to Specific Local Printer Using Its Settings

I can successfully use the code below to print from server side code in ASP.NET to the named local printer (the server has multiple local printers and I cannot set this one to be the default printer).

using (var stream = new FileStream(fileName, FileMode.Open))
{
using (var viewer = new Aspose.Pdf.Facades.PdfViewer())
{
viewer.BindPdf(stream);
viewer.AutoResize = true;
viewer.AutoRotate = true;
viewer.PrintPageDialog = false;

var printerSettings = new System.Drawing.Printing.PrinterSettings();
printerSettings.PrinterName = “my printer name”;

viewer.PrintDocumentWithSettings(printerSettings);

viewer.Close();
}
}

In the particular case, it seems to use all of the printer settings with the exception of the proper output bin. It always sends it to the top bin instead of the left bin defined in the printer properties on the server. Printing a test page from the windows dialog in Devices and Printers sends the test page to the proper left bin. So, I know I have the local printer set up correctly.

I don’t see a setting in the PrintSettings class for output bin. Is the use of this class to define the printer name forcing this to print out to the top bin by default?

Hoping you folks could shed some light on the issue for me.

Hi there,


Sorry for the delayed response. Please check following code for setting printer tray. Hopefully it will serve the purpose.

//create objects for printer and page settings and PrintDocument<o:p></o:p>

System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();<o:p></o:p>

System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();<o:p></o:p>

<o:p></o:p>

//specify your printer name<o:p></o:p>

ps.PrinterName = myPrinterName;<o:p></o:p>

//set PageSize (if required)<o:p></o:p>

pgs.PaperSize = new System.Drawing.Printing.PaperSize(“A4”, 827, 1169);<o:p></o:p>

//set PageMargins (if required)<o:p></o:p>

pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);<o:p></o:p>

//Here you can set the PaperSource which you want to use as per your printer.<o:p></o:p>

pgs.PaperSource = ps.PaperSources[1];<o:p></o:p>

//print document using printer and page settings<o:p></o:p>

viewer.PrintDocumentWithSettings(pgs, ps);




Please feel free to contact us for any further assistance.


Best Regards,

A property named “PaperSource” determines the output bin? I would think something like determines which bin the paper comes from.

Hi Robbe,


From output bin, do you mean the tray to which the printout will be sent ? Please acknowledge so we may reply accordingly.

That’s exactly what I mean. I thought that by not specifying it in one of your settings classes that it would use what was defined on the server with the local printer entry in the Printers section of the control panel. That doesn’t appear to work.

Hi Robbe,


Thanks for your feedback. Papersource property specifies source paper tray. As suggested in above code snippet, PrinterSetting.PaperSources collection gets available trays that are available on printer and assign to PaperSetting.PaperSource property. Please try it hopefully it will serve the purpose.

pgs.PaperSource=ps.PaperSources[1];


Please let us know, if we can be of any further assistance.

Best Regards,

As stated in my post above, I don’t want the paper “source” tray. I need to set a specific paper “target” bin where the printed PDF will be sent to (the Left - it defaults to the top bin now). I don’t see a property for that on your classes and it seems to ignore the defined printer preferences set up on the server for this particular printer.

Hi Robbe,


Thanks for your feedback and we apologize for the misunderstanding.

I’m afraid currently Aspose.Pdf doesn’t support controlling output bin. I’ve logged an investigation ticket as PDFNEWNET-35708 for the requirements in our issue tracking system for further investigation and resolution. We will keep you updated about the issue progress via this forum thread.

Best Regards,