IRONSOFTWAREHOME
Responsive HTML to PDF
from ironpdf import *

# Instantiate Renderer
renderer = ChromePdfRenderer()

# Choose Screen or Print CSS media

renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Screen

# Set the width of the responsive virtual browser window in pixels
renderer.RenderingOptions.ViewPortWidth = 1920

# Set paper mode to automatic fit to physical paper
renderer.RenderingOptions.FitToPaperMode = FitToPaperModes.AutomaticFit

# Render an HTML file
pdf = renderer.RenderHtmlFileAsPdf("Responsive.html")
pip install ironpdf
Responsive HTML to PDF

Responsive HTML to PDF

IronPDF for Python allows you to control the virtual browser viewport width used during rendering, ensuring responsive HTML layouts are captured at the correct breakpoint.

Getting Started

Set CssMediaType, ViewPortWidth, and FitToPaperMode on a ChromePdfRenderer instance before calling a render method. These three settings work together to control how the page layout is evaluated and scaled to fit the PDF paper size.

Understanding the Code

  • CssMediaType = PdfCssMediaType.Screen: Applies @media screen CSS rules instead of print styles. Use this when the page has a responsive desktop layout you want to preserve.
  • ViewPortWidth = 1920: Sets the width of the virtual browser window in pixels. The page will lay out as if viewed in a 1920px-wide browser, activating the appropriate responsive breakpoints.
  • FitToPaperMode = FitToPaperModes.AutomaticFit: Scales the rendered content to fit within the physical PDF page dimensions automatically, avoiding cropped or overflowing content.
  • RenderHtmlFileAsPdf("Responsive.html"): Renders a local HTML file using the configured viewport settings.

Choosing the Right Viewport Width

Match ViewPortWidth to the breakpoint your HTML is designed for. Common values are:

  • 1920 - Full HD desktop layout
  • 1280 - Standard widescreen desktop
  • 768 - Tablet/medium breakpoint
  • 375 - Mobile layout
Learn to convert HTML to PDF with IronPDF for Python!

Ready to Get Started?

Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Python Module Download for PDF
Install with pip

Version: 2026.9

  1. Download and install Python 3.7+.
  2. Install pip from pypi.org if it isn't installed already.
  3. Execute the above command in the terminal.
Python PDF Module
Download Module

Version: 2026.9

Manually install into your project

  1. Download the package
  2. Run this command from the terminal
    pip install ironpdf-2026.9-py37-none-win_amd64.whi

Licenses from $999