Rendering Settings for HTML to PDF

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

// Apply your license key
License.setLicenseKey("YOUR-LICENSE-KEY");

// Set a log path
Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));

// Create a new ChromePdfRenderOptions object
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();

// Set custom options for the generated PDF document (paper size, title, etc.)
renderOptions.setCustomPaperSizeInCentimeters(31.75, 50.80 );
renderOptions.setPrintHtmlBackgrounds(true);
renderOptions.setPaperOrientation(PaperOrientation.LANDSCAPE);
renderOptions.setTitle("My PDF Document Name");
renderOptions.setEnableJavaScript(true);
renderOptions.setWaitFor(new WaitFor(50)); // time in milliseconds
renderOptions.setCssMediaType(CssMediaType.SCREEN);
renderOptions.UseScaledRendering(100); // 100 is zoom percentage
renderOptions.setCreatePdfFormsFromHtml(true);

// Customize PDF Margins by specifying sizes in millimeters
renderOptions.setMarginTop(40);
renderOptions.setMarginBottom(40);
renderOptions.setMarginLeft(20);
renderOptions.setMarginRight(20);

// Render the HTML document as a PDF using the specified rendering options.
try {
    PdfDocument pdf = PdfDocument.renderHtmlFileAsPdf("wikipedia.html", renderOptions);
    pdf.saveAs(Paths.get("assets/wikipedia.pdf"));
} catch (IOException e) {
    e.printStackTrace();
}
mvn install
Rendering Settings for HTML to PDF

Rendering Settings for HTML to PDF

This code example demonstrates the power and flexibility that IronPDF provides developers in converting HTML content into PDF documents.

ChromePdfRenderOptions ensures that developers have total control over how web pages are converted into PDFs.

With the ChromePdfRenderOptions class, developers can customize page margins, specify page orientations, add annotations, include bookmarks, change document metadata, adjust zoom scaling, modify CSS rule sets, and much more. Once defined, objects of this class can be supplied as a second (optional) parameter to any of the static PDF document rendering methods (renderHtmlAsPdf, renderHtmlFileAsPdf, and renderUrlAsPdf) to alter how IronPDF interprets website content, as well as how it renders the PDF content during these methods' execution.

Explore ChromePdfRenderOptions Customizations in API Reference for the detailed list of available customizations in the API Reference.

Learn How to Create PDFs with Java and IronPDF
View on GitHub

Ready to Get Started?

Version:2026.10just released