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.

Is there any movement for this? I am trying to print to a label printer and the checkbox is also what works for my needs.

@cstaub

We are afraid that the earlier logged ticket could not get resolved due to other issues in the queue. We have recorded your concerns and will surely inform you as soon as we make some progress towards its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFNET-49934) have been fixed in Aspose.PDF for .NET 24.4.

@cstaub

Beginning with Aspose.PDF 24.4 this preference can be switched on and off using the Document.PickTrayByPdfSize property or the PdfContentEditor facade:

using (Document document = new Document())
{
    Page page = document.Pages.Add();
    page.Paragraphs.Add(new TextFragment("Hello world!"));

    // Set the flag to choose a paper tray using the PDF page size
    document.PickTrayByPdfSize = true;
    document.Save("result.pdf");
}
using (PdfContentEditor contentEditor = new PdfContentEditor())
{
    contentEditor.BindPdf("input.pdf");

    // Set the flag to choose a paper tray using the PDF page size
    contentEditor.ChangeViewerPreference(ViewerPreference.PickTrayByPDFSize);
    contentEditor.Save("result.pdf");
}

49934.pdf (1.9 KB)