Custom PDF Size

import com.ironsoftware.ironpdf.*;  
import com.ironsoftware.ironpdf.render.*;  
import java.io.IOException;  
import java.nio.file.Paths;

String html = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>";  
  
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();  
renderOptions.setPaperSize(PaperSize.Custom);  
  
/*  
 * Setting page sizes using different measuring units: * 1. setCustomPaperWidth( width ) / setCustomPaperHeight( height ): for inches * 2. setCustomPaperSizeInCentimeters( width, height ): for centimeters. * 3. setCustomPaperSizeInMillimeters( width, height ): for millimeters * 4. setCustomPaperSizeInPixelsOrPoints( width, height ): for pixels/points */renderOptions.setCustomPaperSizeInCentimeters(13.97, 13.97);  
  
PdfDocument.renderHtmlAsPdf(html, renderOptions).saveAs(Paths.get("assets/CustomPaperSize.pdf"));
mvn install
Custom PDF Size

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.).

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:

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.

Learn more about setting custom PDF sizes with IronPDF.
View on GitHub

Ready to Get Started?

Version:2026.10just released