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

Free Support Forum - aspose.com

How to set PaperSize for Print

Hi is it sufficient to set the Doocument PaperSize(assume that’s the PaperSize available from the Printer) in order to change/set the paper size using Aspose’s “Document.Print(PrinterSettings)”?.

Like the code snippet below:

 public static void SetupPaperSize(Document doc, PaperSize pSize)
        PaperSize defaultPaperSize = 0;
        defaultPaperSize = doc.Sections[0].PageSetup.PaperSize;
        foreach (Section section in doc.Sections)
            defaultPaperSize = section.PageSetup.PaperSize;
            section.PageSetup.PaperSize = pSize;

        InfoLog.Info($" : Node : Paper size changed from {defaultPaperSize.ToString()} to {pSize.ToString()}");

How about the ‘DefaultPageSettings.PaperSize’ for the printerSettings passed to the Print method, is that need to be changed as well for the PaperSize change for Print. One thing I noticed is that PaperSize from Microsoft is taking a ’ System.Drawing.Printing’, which is different from Aspose’s PaperSize.


@DougT I think in your case, you should also specify paper tray. Please see the code example in this article. It shows how to specify different paper trays for pages with different paper size.

Thanks Alexey, in the example, it’s also setup paper tray based on paper size. I’ll add it in my code.

It’s not clear from the example, but I guess basically you knew that tray is “A4” paper because the SoureName is “A4” and you figure the other is Letter bases on the SourceName for that PaperSouce?

So you are saying that as long as I setup the document’s PaperSize and PapserSource correctly for the specified printer. I don’t need change the “DefaultPageSettings” as well?

@DougT The paper tray value stored in documents is printer specific. So, yes, you should know what paper size is in the specified tray.
It is not required to specify DefaultPageSettings.PaperSize if the page size and tray is configured properly.

Thanks Alexey for your help.