Render your HTML in a live preview and save it as a PDF using your browser's built-in print dialog. Select "Save as PDF" in the print destination for a perfect, CSS-styled PDF.
Modern browsers include a high-quality PDF rendering engine in their print dialog. This tool renders your HTML in an invisible iframe (a sandboxed browser frame), then triggers the browser's window.print() function on that frame. When you select "Save as PDF" (Chrome/Edge) or "PDF" (Firefox/Safari) in the print destination dropdown, the browser renders all HTML, CSS, and inline styles to a PDF exactly as they appear visually on screen. Convert a Word document to HTML first using our Word to HTML converter, then paste the output here to generate your PDF. If the HTML contains messy inline styles, run it through our html cleaner online first for a more predictable PDF output.
To control how your HTML looks in the generated PDF, use the CSS @media print rule. Print media queries let you: hide navigation and buttons (display:none), set page margins (@page { margin: 2cm; }), control page breaks (page-break-before: always or break-before: page), and specify paper size (@page { size: A4; }). These rules only apply when the browser renders to print/PDF and are ignored during normal screen rendering.
width in your CSS — the PDF page width depends on the print dialog's paper size setting@page { margin: 1.5cm; } to set consistent margins across all pagesposition: fixed elements — they repeat on every PDF pagepage-break-inside: avoid on tables and figures to prevent them splitting across pagesIn Chrome and Edge's print dialog: (1) Select "Save as PDF" as the destination. (2) Enable "Background graphics" (under "More settings") so background colours and images appear. (3) Set margins to "None" if your CSS already handles margins with @page. (4) Choose the correct paper size (A4, Letter, etc.). The Brave browser and Firefox may render PDFs slightly differently due to different print engine implementations.
Yes. For server-side HTML to PDF conversion: wkhtmltopdf (uses the WebKit rendering engine, free, command-line), Puppeteer (headless Chrome via Node.js — page.pdf()), WeasyPrint (Python, CSS Paged Media support), or commercial APIs like PDFShift or API2PDF. Puppeteer produces the closest match to what a user sees in Chrome and supports modern CSS including flexbox and grid.
Browser security restrictions prevent iframes from loading external images when the page is sandboxed. To include images in your PDF: embed them as Base64 data URIs (<img src="data:image/png;base64,...">), or host your HTML page on a server and print it from there. You can use our Base64 Encoder to convert image files to data URIs.