Custom PDF Size

With IronPDF, developers can generate PDF documents with dimensions sized other than the standard A4 (8½ by 11 inches, or 21.59 by 27.94 centimeters).

Render PDFs with different paper sizes by specifying the desired dimensions in a ChromePdfRenderOptions object with the setPaperSize method. Set the paper size in the method argument with a preset PaperSizes value. Afterward, render the PDF document as usual from the source content (HTML string, URL, HTML file, etc.).

ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();  
renderOptions.setPaperSize(PaperSize.B5);  
PdfDocument.renderHtmlFileAsPdf("mycontent.html", renderOptions);
JAVA

The PaperSize enum type supports over 100 industry-recognized print sizes. This provides coverage for those sizes used in the majority of business cases. To use a different print size other than the ones included in the PaperSize enum, choose PaperSize.Custom and set the desired page width and page height manually:

ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();  
renderOptions.setPaperSize(PaperSize.Custom);  
renderOptions.setCustomPaperWidth(11);   // in inches  
renderOptions.setCustomPaperHeight(17);  // in inches
JAVA

As shown above, setCustomPaperWidth and setCustomPaperHeight accept number values representing the desired dimensions in inches. To set the dimensions using centimeters, use setCustomPaperSizeInCentimeters. To set the dimensions in millimeters, use setCustomPaperSizeInMillimeters. For pixels/points, use setCustomPaperSizeInPixelsOrPoints.