PaperSource when print PDF files

Aspose.Pdf 9.5.0.0
Edit: Just tried with Aspose.Pdf 9.9.0.0; Same result.
Edit: Just tried with Aspose.Pdf 10.1.0.0; Same result.
Edit: Attached copy of pdf file, used for testing.
Edit: Just wanted to comment, that this behavoir is consistent across 3 different brands Lexmark MFC Printers, 2 Xerox copiers and one minolta copier. (PS and PCL5/6 printer drivers)
Edit: (Lots of them, sorry) - This occures if I select Tray 1, or Tray 2, not just Manual Tray.

I have a PDF file (Created using Aspose.Pdf),
Aspose.Pdf.Facades.PdfViewer viewer = new Aspose.Pdf.Facades.PdfViewer();
viewer.BindPdf("AsposePdfTestFile.pdf");

which I attempt to print to manual tray, using either:

viewer.PrintDocumentWithSettings(prtSettings);

or

PageSettings pageSettings = new PageSettings(prtSettings);
viewer.PrintDocumentWithSettings(pageSettings, prtSettings);

Inspecting the pageSettings.PaperSource or prtSettings.DefaultPageSettings.PaperSource displays "PaperSource=[PaperSource Manual Tray Kind=Custom]", but the printed result is sent to "Automatic tray". Which is the printers default setting.

PaperSource is set by:

String Print_Name = "MyPrinter"
String Print_Tray = "Manual tray"

PrintDocument Doc = new PrintDocument();
Doc.PrinterSettings.PrinterName = Print_Name;
prtSettings = Doc.PrinterSettings;

PaperSource pkSource;
for (int i = 0; i < prtSettings.PaperSources.Count; i++) {
pkSource = prtSettings.PaperSources[i];
if (pkSource.SourceName == Print_Tray) {
pSet.DefaultPageSettings.PaperSource = pkSource;
break;
}
}

Sanity test 1:
Creating a document in Microsoft Word, Printing to MyPrinter, Tray: Manual Tray.
Result is sent to printer, manual tray.

Sanity test 2:
Opening the same aspose pdf file, in Adobe Reader, and printing to Manual Tray,
Result is sent to printer, manual tray.

Hi Jens,


Thanks for using our API’s.

We are working over this query and will get back to you soon.

Hi Jens,

Thanks for your inquiry. As per my understanding you want to set a source paper tray. Please check following code snippet for the purpose, you need to set PaperSource property of PageSetting object. Please also check Aspose.Pdf printing options and sample code snippet to use subjected properties.

Moreover, If there is any difference in my understanding and your requirement then please share some more details about your requirement. So we will look into it and guide you accordingly.

//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;
ps.PrintRange = PrintRange.SomePages;
ps.FromPage = 1;
ps.ToPage = 2;
//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);

Please feel free to contact us for any further assistance.

Best Regards,

Hello,


After some testing, I seam to have concluded, that if I set the PrinterSettings.DefaultPageSettings.PaperSource,
the printet output fails to set the correct tray.

If I create the PageSettings using the PrinterSettings, it fails.

If I create a separate PageSettings object, and specifically set its PaperSource, it seams to work.

As described in the original post, in ALL cases, inspecting pgs.PaperSource before printing, displays: the PaperSource property as “Manual tray”, as expected…

Here is the source for reproducing the error,
setting flag to 0, 1 or 2 produces test cases.
0: fails.
1: fails.
2: works.

int flag = 0;
while (flag < 3) {
string myPrinterName = “500. CS510”;

// Load Test PDF
Aspose.Pdf.Facades.PdfViewer viewer = new Aspose.Pdf.Facades.PdfViewer();
viewer.BindPdf(@“C:\Dev\AsposeTest\Resources\test.pdf”);

// Create Printer settings.
System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();
ps.PrinterName = myPrinterName;
ps.DefaultPageSettings.PaperSource = ps.PaperSources[6];

System.Drawing.Printing.PageSettings pgs = null;
if (flag == 2) {
// This works.
pgs = new System.Drawing.Printing.PageSettings();
pgs.PaperSource = ps.PaperSources[6];

viewer.PrinterJobName = “Manual PageSetting”;
} else if (flag == 1) {
// Fails.
pgs = new System.Drawing.Printing.PageSettings(ps);

viewer.PrinterJobName = “PageSetting from PrinterSettings”;
} else {
viewer.PrinterJobName = “No PageSetting”;
}

Console.WriteLine("Jobname: " + viewer.PrinterJobName);
Console.WriteLine("Printer default page papersource: " + ps.DefaultPageSettings.PaperSource);

if (pgs != null) {
Console.WriteLine("Page settings papersource: " + pgs.PaperSource);

// Print document using printer and page settings
viewer.PrintDocumentWithSettings(pgs, ps);
} else {
Console.WriteLine(“Page settings papersource: NONE”);

// Print document using printer settings only.
viewer.PrintDocumentWithSettings(ps);
}

// Close Test PDF.
viewer.Close();

// Inset blank line in output.
Console.WriteLine();
flag++;
}
}


Attached is screen captures of each case.

Using test case 2, I can work around the issue, but I believe you have an issue, as I think test case 0 and 1 ought to work?

Regards, Jens.

Hi Jens,


Thanks for your feedback. It is good to know that suggested option, 2 is working. However we have logged an investigation ticket PDFNEWNET-38233 to look into other two options for setting source tray and PaperSource Property value. We will keep you updated about the issue resolution.

Best Regards,

The issues you have found earlier (filed as PDFNET-38233) have been fixed in Aspose.PDF for .NET 24.7. This message was posted using Bugs notification tool by asad.ali