HTML to PDF

This code example illustrates how IronPDF can transform raw HTML content into high-quality, pixel-perfect PDF documents. IronPDF can render HTML markup with a simple structure (like the one given in the example above), and more complex markup that incorporates nested elements, stylesheet declarations, and JavaScript interactions.

Behind the scenes, IronPDF utilizes a built-in Chrome rendering engine to interpret HTML, JavaScript, and CSS content as proper web content before translating it accurately into its equivalent PDF-based representation. This ensures that IronPDF outputs PDFs whose content appears the same way that it would appear in a standards-compliant web browser.

IronPDF's PdfDocument class provides several static methods that allow Java developers to render HTML content from different sources. PdfDocument.renderHtmlAsPdf, as shown in the example above, transforms a string containing HTML markup into its PDF form. To convert web content located on a local network or across the Internet, call the PdfDocument.renderUrlAsPdf, which accepts a string containing the URL of the web page to be rendered. For HTML files saved to a local file system directory, specify their paths in calls to the PdfDocument.renderHtmlFileAsPdf method.

Developers can customize the appearance of the PDF documents returned from the three previous methods using the ChromePdfRenderOptions class. Refer to the API specification for the ChromePdfRenderOptions for more information.