Format GuidesMarch 13, 2026

Convert HTML to PDF: The Complete Guide

Converting HTML to PDF is a task that spans many different use cases — saving a webpage for offline reading, generating invoices or reports from web applications, archiving online content, or producing print-ready documents from web-based data. Each scenario has its own optimal approach, and using the wrong method can result in PDFs that miss images, break layouts, or cut off content mid-page. HTML and PDF are fundamentally different formats. HTML is a fluid, responsive layout format designed for screens that can reflow content to any width. PDF is a fixed-layout format designed for print. The conversion process must translate the flexible web layout into a rigid page grid — this is where most problems arise. This guide covers the full landscape of HTML-to-PDF conversion: built-in browser printing, dedicated online tools, command-line solutions for developers, and best practices for generating clean, well-formatted PDFs from any web content.

Converting a Web Page to PDF Using Your Browser

Every major web browser has a built-in Print to PDF feature that lets you save any webpage as a PDF in seconds. This is the simplest method and works for casual use — saving receipts, archiving articles, or keeping records of web content. To get the best result from browser printing, always use Print Preview before saving. Modern browsers offer a 'More settings' or 'Advanced' panel where you can control margins, page size, orientation, and whether to include or exclude background colors and images. Excluding backgrounds saves ink when printing and simplifies the PDF for archiving, but including them is necessary if the page design relies on colored backgrounds for readability. The limitation of browser printing is that it captures the page at its current rendered state in the browser — at the current scroll position and window size. For responsive pages, printing at a narrow browser width may produce a mobile layout. For best results, widen your browser window to full screen before printing so the desktop layout is captured.

  1. 1Open the webpage you want to convert in your browser.
  2. 2Press Ctrl+P (Windows/Linux) or Cmd+P (Mac) to open the Print dialog.
  3. 3Set the destination to 'Save as PDF'.
  4. 4Open 'More settings' and choose paper size, margins, and whether to include backgrounds.
  5. 5Check the print preview on the right side — scroll through all pages to verify layout.
  6. 6Click Save and choose a location for your PDF file.

Using an Online HTML-to-PDF Converter

Online HTML-to-PDF converters offer more control than browser printing, especially for preserving exact web layouts, loading JavaScript-rendered content, and handling pages that use custom fonts or complex CSS. LazyPDF's HTML-to-PDF tool accepts a URL or a raw HTML file, renders it in a headless browser engine, and exports the result as a multi-page PDF. When converting by URL, the tool fetches the live page including all linked stylesheets, images, and fonts. For pages behind a login or paywall, you cannot convert by URL — instead, you need to save the HTML source locally. In Chrome, go to File > Save Page As > 'Webpage, Complete' to save the HTML and all assets, then upload the saved HTML file to the converter. For single-page web apps that render content with JavaScript (React, Vue, Angular), make sure the converter uses a JavaScript-capable headless browser rather than a simple HTML parser. LazyPDF uses LibreOffice with JavaScript rendering enabled, so dynamic content is captured correctly.

  1. 1Go to LazyPDF and open the HTML to PDF converter.
  2. 2Enter the webpage URL or upload a saved .html file.
  3. 3Choose paper size and orientation if options are available.
  4. 4Wait for the headless browser to render and convert the page.
  5. 5Download the resulting PDF and verify that images, fonts, and layout are correct.

Converting HTML Files to PDF for Developers

Developers who need to generate PDFs programmatically from HTML have several excellent options. wkhtmltopdf is a widely used open-source command-line tool that renders HTML using WebKit and produces clean PDF output. Puppeteer and Playwright are headless Chrome/Chromium libraries for Node.js that offer the highest fidelity HTML rendering available. For server-side invoice and report generation, libraries like WeasyPrint (Python) and mPDF (PHP) convert HTML and CSS to PDF on the server without requiring a browser engine. These are lighter weight than headless browser solutions and more predictable for well-structured HTML. The key to high-quality programmatic conversion is writing clean, print-aware CSS. Use `@media print` rules to hide navigation elements, define explicit page breaks with `page-break-before` and `page-break-after`, and use cm or mm units for margins rather than pixels. Setting a fixed viewport width in your headless browser (typically 1200px or A4 width in pixels) ensures consistent layout across all conversions.

  1. 1Install wkhtmltopdf or set up Puppeteer/Playwright in your project.
  2. 2Add @media print CSS rules to hide headers, footers, and nav elements.
  3. 3Set explicit page-break-before rules for major sections or report boundaries.
  4. 4Run the conversion and test output at different content lengths to verify page breaks behave correctly.

Preserving Links, Images, and Fonts in HTML PDFs

Hyperlinks in HTML become clickable links in the PDF output when using a proper rendering engine. Browser Print to PDF preserves links. Online converters using headless browsers also preserve links. Simple HTML parsers (not browser-based) may not preserve link interactivity — test your tool by clicking a link in the output PDF. Images in HTML-to-PDF conversion must be accessible at conversion time. Images with relative paths may not load if the HTML is converted without its accompanying asset folder. Always use absolute paths (full URLs) for images in HTML files intended for PDF conversion, or upload the full HTML package including all image files. Custom web fonts loaded via @import or Google Fonts URLs will only render correctly if the conversion engine has internet access to fetch them. For offline conversions, embed fonts using base64-encoded data URIs in your CSS, or host the font files locally alongside the HTML.

Frequently Asked Questions

Why is the web page layout broken in my HTML PDF?

Web page layouts break in PDF conversion for several reasons: CSS media queries that change layout for print, flexible grid or flexbox layouts that behave differently at fixed widths, JavaScript-rendered content not loading, or fixed-position elements like sticky headers appearing on every page. Fix this by adding @media print CSS rules that set explicit widths, remove fixed-position elements, and simplify multi-column layouts to single columns for the page width. Always test your print CSS before converting.

How do I convert a webpage that requires a login to PDF?

Online URL-based converters cannot access pages that require authentication. To convert protected pages, log in with your browser, navigate to the page you want, then use the browser's Print to PDF function (Ctrl+P > Save as PDF). Alternatively, save the page as a complete HTML file (File > Save Page As > Webpage, Complete) and upload the saved HTML file to an offline converter. For developers, use Puppeteer or Playwright, which let you write authentication flows before triggering the PDF export.

Can I convert multiple HTML pages into a single PDF?

Yes, but the method depends on your tool. Browser printing converts one page per print session. To combine multiple web pages into one PDF, convert each page separately to PDF first, then merge the PDF files using a PDF merge tool like LazyPDF's merge function. For developers, tools like Puppeteer can loop through multiple URLs and append each page's content into a single PDF document programmatically. This is the preferred approach for generating multi-section reports from multiple web pages or API endpoints.

Why are background colors and images missing from my HTML PDF?

Browsers and converters often disable background printing by default to save ink. In the browser Print dialog, open 'More settings' and check 'Background graphics' to include backgrounds. In online converters, look for a 'Print background' or 'Include backgrounds' option. For programmatic tools like wkhtmltopdf, add the flag '--background' or '--print-media-type false' to force background rendering. This is especially important for styled HTML emails, branded reports, or any design where background colors are part of the visual identity.

Convert any web page or HTML file to a clean, professional PDF. Works with URLs and local HTML files — no registration needed.

Convert HTML to PDF

Related Articles