HTML to PDF
from ironpdf import *

# Instantiate Renderer
renderer = ChromePdfRenderer()
 
# Create a PDF from a HTML string using Python
pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")
 
# Export to a file or Stream
pdf.SaveAs("output.pdf")

# Advanced Example with HTML Assets
# Load external html assets: Images, CSS and JavaScript.
# An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", r"C:\site\assets")
myAdvancedPdf.SaveAs("html-with-assets.pdf")
pip install ironpdf
HTML to PDF

HTML to PDF

This code example illustrates IronPDF for Python's flagship HTML to PDF conversion capability.

Python developers can use the RenderHtmlAsPdf method to convert raw HTML markup into PDF documents. IronPDF can render all HTML content faithfully into its equivalent PDF form. This includes this simple "Hello World" example featured above and also more complex HTML structures consisting of nested elements.

As shown above, the RenderHtmlAsPdf method accepts a string containing the HTML markup to be rendered into a PDF. Note that the method also recognizes images, iframes, and other externally-referenced assets included in the HTML string. Such elements are rendered in generated PDFs as expected for standards-compliant browsers.

Customize PDF documents generated with the RenderHtmlAsPdf method with specialized headers, footers, margins, and other page settings. See this code example for more information.

Learn to Convert HTML to PDF in Python - Tutorial
View on GitHub

Ready to Get Started?

Version:2026.11just released