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

Free Support Forum - aspose.com

Set Choose paper source by PDF page size

Hello,

We are current trying to convert our code for iTextSharp to Aspose.PDF. We are encountering an issue where we cannot find an equivalent line for:
using (var stamper = new PdfStamper(reader, destStream))
{
stamper.AddViewerPreference(PdfName.PICKTRAYBYPDFSIZE, PdfBoolean.PDFTRUE);
}

This sets the checkbox Choose paper source by PDF page size in the printer dialog. Is there an equivalent or a recommended workaround?
Thanks,
Colin

@StatePeon

In order to set paper size during printing, you can specify it in printer settings like in the below sample code snippet using Aspose.PDF:

using (FileStream originalPdfStream = new FileStream(dataDir + "Sample.pdf", FileMode.Open))
{
 Facades.PdfViewer pdfViewer = new Facades.PdfViewer();
 pdfViewer.BindPdf(originalPdfStream);

 int a4PaperWidthAsHundrethOfInch = 827;
 int a4PaperHeightAsHundrethOfInch = 1169;

 System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings
 {
  Copies = 1,
  PrinterName = "Microsoft Print to PDF",
  PrintToFile = true,
  PrintFileName = dataDir + "printotfile.pdf"
 };

 System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings
 {
  Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0),
  PaperSize = new System.Drawing.Printing.PaperSize("A4", a4PaperWidthAsHundrethOfInch, a4PaperHeightAsHundrethOfInch),
  PrinterSettings = printerSettings
 };

 pdfViewer.PrintPageDialog = false;
 pdfViewer.PrintDocumentWithSettings(pgs, printerSettings);
}

Please feel free to let us know in case you notice any issue.

Thank you for your response. However that is not quite what my question was. Our code originally was able to select the “Choose paper source by PDF page size.” My question is does Aspose.PDF have a way to set this through the API?

Thanks,
Colin

@StatePeon

We have logged an investigation ticket as PDFNET-49934 in our issue tracking system to further analyze whether your requirements are feasible to achieve using the API or not. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thanks for the reply. Will await the result of the investigation.

1 Like

Hello, has there been any progress with this? We are also running into this issue for documents with both Portrait and Landscape Orientations in it.

Thanks

@InfoEdGlobal

We regret to inform you that the earlier logged ticket is not yet resolved. We will surely investigate and resolve it on a first come first serve basis and let you know once is is fixed. Please spare us some time.

We are sorry for the inconvenience.