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 PaperSize value. Afterward, render the PDF document as usual from the source content (HTML string, URL, HTML file, etc.).

// Create an instance of ChromePdfRenderOptions
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();  

// Set the paper size to B5 using the predefined PaperSize enum
renderOptions.setPaperSize(PaperSize.B5);  

// Render the HTML file "mycontent.html" as a PDF using the specified paper size
PdfDocument.renderHtmlFileAsPdf("mycontent.html", renderOptions);
// Create an instance of ChromePdfRenderOptions
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();  

// Set the paper size to B5 using the predefined PaperSize enum
renderOptions.setPaperSize(PaperSize.B5);  

// Render the HTML file "mycontent.html" as a PDF using the specified paper size
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:

// Create an instance of ChromePdfRenderOptions
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();  

// Set the paper size to Custom to allow manual dimension specification
renderOptions.setPaperSize(PaperSize.Custom);  

// Set the custom paper width to 11 inches
renderOptions.setCustomPaperWidth(11);   // in inches  

// Set the custom paper height to 17 inches
renderOptions.setCustomPaperHeight(17);  // in inches
// Create an instance of ChromePdfRenderOptions
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();  

// Set the paper size to Custom to allow manual dimension specification
renderOptions.setPaperSize(PaperSize.Custom);  

// Set the custom paper width to 11 inches
renderOptions.setCustomPaperWidth(11);   // in inches  

// Set the custom paper height to 17 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.