Custom Fonts in HTML to PDF
from ironpdf import *
 
html_with_font = '''<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet">
                   <p style="font-family: \'Lobster\', serif; font-size:30px;" > Hello Google Fonts</p>'''
 
# Instantiate Renderer
renderer = ChromePdfRenderer()
renderer.RenderingOptions.WaitFor.RenderDelay(500)
 
# Create a PDF from an HTML string
pdf = renderer.RenderHtmlAsPdf(html_with_font)
 
# Export to a file or Stream
pdf.SaveAs("font.pdf")
pip install ironpdf
Custom Fonts in HTML to PDF

Custom Fonts in HTML to PDF

IronPDF for Python fetches and embeds Google Fonts in PDF documents, preserving custom typography from your HTML source exactly as it appears in a browser.

Getting Started

Include a Google Fonts <link> tag in your HTML string and apply the font family via inline CSS or a <style> block. Set a short WaitFor.RenderDelay to allow IronPDF time to download the font file before rendering begins.

Understanding the Code

  • <link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet">: Standard Google Fonts stylesheet link. IronPDF follows this link and downloads the font during rendering.
  • font-family: 'Lobster', serif: Applies the Google Font to the element. The serif fallback is used if the font fails to load.
  • WaitFor.RenderDelay(500): Gives the renderer time to fetch and apply the remote font before capturing the page. Increase this if fonts are still missing in the output.
  • RenderHtmlAsPdf(html_with_font): Renders the HTML - including the remotely loaded font - as a PDF.

Font Embedding

IronPDF embeds the downloaded font directly in the output PDF, ensuring the document displays correctly on any system even without internet access. For production environments with strict outbound network policies, consider hosting fonts locally and referencing them with a BaseUrl.

Learn to convert HTML to PDF with IronPDF for Python!

Ready to Get Started?

Version:2026.11just released