Home › PDF Tools › HTML to PDF Converter

HTML to PDF Converter

Paste your HTML (with its CSS) or open an .html file. The live preview shows how it lays out on the page, including page breaks, and one click saves it as a PDF.

Last updated:

.pdf

Preview

Estimated pages: –
Advertisement
Advertisement

How to use the HTML to PDF Converter

  1. Paste your HTML into the editor, or click Open .html to load a file. Use Sample to try it out.
  2. Pick the page size, orientation and margins.
  3. Check the preview: dashed lines show where each new PDF page starts.
  4. Press Download PDF to save the file, or Print to use your browser's print dialog.

Page width in pixels for common paper sizes

Browsers lay out HTML at 96 CSS pixels per inch, so the width your content gets is (paper width − 2 × margin) in mm × 96 ÷ 25.4. Example: A4 with 15 mm margins gives (210 − 30) × 3.7795 = 680 px of usable width and (297 − 30) × 3.7795 = 1009 px of height per page.

Paper (portrait)SizeFull widthContent width, 10 mm marginsContent width, 15 mm marginsContent height, 15 mm margins
A4210 × 297 mm794 px718 px680 px1009 px
US Letter8.5 × 11 in816 px740 px703 px943 px
Legal8.5 × 14 in816 px740 px703 px1231 px

The preview uses exactly these sizes, so the dashed page-break lines match the PDF.

CSS that works well for PDF output

GoalCSS
Start a section on a new pagepage-break-before: always; or break-before: page;
Keep a box togetherpage-break-inside: avoid;
Readable body textfont-size: 12pt; line-height: 1.5;
Images that never overflowimg { max-width: 100%; height: auto; }
Full-width tablestable { width: 100%; border-collapse: collapse; }
Colored backgroundsWork as written: the PDF is a snapshot of the rendered page

What is kept and what is removed

Your HTML is cleaned before it is shown, so pasted code can never run on this page:

  • Kept: all normal HTML elements, inline style attributes, <style> blocks, classes, tables, lists, SVG and images (including data: images).
  • Removed: <script>, event handlers such as onclick or onerror, javascript: links, iframes, embeds, forms and <link> or @import stylesheets.
  • External resources: CSS url() references to other sites are dropped and remote images only load if the server allows cross-origin use.

Frequently asked questions

Is my HTML uploaded to a server?

No. The page is sanitized, laid out and turned into a PDF by html2pdf.js inside your browser, so your code never leaves your device.

Why were my scripts removed?

Running unknown JavaScript on this page would be a security risk, so the code is cleaned with DOMPurify before it is shown. Scripts, event handlers such as onclick, iframes, forms and external stylesheets are removed. Static HTML and CSS stay exactly as written.

Is the text in the PDF selectable?

html2pdf.js takes a high-resolution snapshot of each page, so the PDF looks exactly like the preview, but the text is part of the image and cannot be selected or searched. Use the Print button and choose Save as PDF if you need selectable text.

Why don't my external images appear?

Images on other websites only show up if that server allows cross-origin access. For reliable results, use images on the same site as the code, or embed them as data: URLs.

How do I force a page break?

Add style="page-break-before: always" (or break-before: page) to the element that should start on a new page. The converter also avoids cutting through images where it can.

What page width does the HTML get?

The content area equals the paper width minus the margins. On A4 with 15 mm margins that is 180 mm, or about 680 CSS pixels, so design for roughly that width.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

Word to PDFConvert Word DOCX documents to PDF.Image to PDFConvert JPG, PNG, WEBP and more into a PDF.Merge PDFCombine several PDF files into one document.Compress PDFReduce PDF file size while keeping it readable.Add Bookmarks to PDFAdd, edit and nest PDF bookmarks (outline) or auto-generate them from headings, in your browser.HTML Editor (Live Preview)Write HTML, CSS and JavaScript and see a live, sandboxed preview as you type.Online Word ProcessorFree browser word processor with headings, lists, tables and images. Autosaves; export DOCX or PDF.Text to HTML ConverterTurn plain text into clean HTML: paragraphs, line breaks, links, lists and escaped entities.JPG to PDFCombine JPG photos into one PDF with page size, margins and orientation options.PowerPoint to PDFConvert PPTX slides to PDF, one page per slide at the original slide size. Batch files, no upload.OCR PDFMake scanned PDFs searchable and copyable with OCR in 70+ languages, or export the text.PDF to WordConvert PDF files to editable Word documents.PDF to ExcelExtract tables from PDF files into an Excel spreadsheet (XLSX) or CSV, right in your browser.PDF to JPGTurn PDF pages into high-quality JPG images.PDF to PNGConvert PDF pages to PNG images with custom DPI and transparent background.PDF to Text ConverterExtract the text from any PDF page by page, then copy it or save it as a TXT file.Text to PDF ConverterTurn plain text or a .txt file into a clean PDF with your font, size, margins and page size.Markdown to PDF ConverterWrite or paste Markdown, preview it with a clean theme and export a polished PDF in seconds.Excel to PDF ConverterConvert Excel and CSV sheets into tidy, paginated PDF tables with repeated headers.Extract Images from PDFPull every embedded photo and graphic out of a PDF as PNG or JPG, or save pages as images.PDF to PowerPointTurn every PDF page into a PowerPoint slide (PPTX) in 16:9, 4:3 or the PDF's own size.PDF to MarkdownConvert PDF to clean Markdown with headings, lists, tables, bold, italics and links.PDF to HTMLConvert PDF to a clean, responsive HTML page or an exact positioned layout, in your browser.PDF to Long ImageStitch all PDF pages into one tall PNG or JPG image, with gap, width and page range options.PNG to PDFConvert PNG images to one PDF, keeping transparency or filling it with white or any color.HEIC to PDFConvert iPhone HEIC photos into one PDF in your browser, with page size, margins and reordering.CSV to PDFTurn a CSV file into a clean, paginated PDF table with repeating headers.EPUB to PDF ConverterConvert EPUB e-books to PDF with images, page size, font size, margins and clickable bookmarks.PDF to TIFF ConverterConvert PDF pages to multi-page or single-page TIFF in color, grayscale or black and white.RTF to PDF ConverterConvert RTF documents to PDF with fonts, tables, images and page size options.SVG to PDF ConverterConvert SVG files to vector PDF with page size and fit options, or merge many SVGs into one PDF.TIFF to PDF ConverterConvert single and multi-page TIFF scans to PDF with page size and compression options.WEBP to PDF ConverterConvert one or many WEBP images to a PDF with page size, margins, layout and reordering.Add Image to PDFPlace a logo, photo or signature image on any PDF page. Drag, resize, rotate and set opacity.Compress PDF to 100KBShrink a PDF to 100KB or less automatically, keeping every page and page size.HTML to Word ConverterConvert HTML code or pasted rich text into an editable Word .docx document.Image to Word ConverterTurn JPG, PNG or screenshot text into an editable Word (.docx) document with OCR, in your browser.PDF ConverterConvert Word, Excel, PowerPoint, images, text, HTML or EPUB to PDF, and PDF to JPG, PNG, Word or text.LaTeX to PDFCompile LaTeX to PDF in your browser with a TeX engine, live preview, log and PDF download.Merge Word DocumentsCombine several .docx files in any order into one Word document, with page or section breaks.PDF to FlipbookTurn a PDF into a page-turning flipbook with zoom and fullscreen, and export it as an HTML ZIP.PowerPoint ViewerOpen and present .pptx files in your browser with thumbnails, speaker notes and full screen.Whiteboard Photo to PDFClean up whiteboard and blackboard photos: straighten, remove glare, whiten, then save as PDF.DjVu to PDFConvert DjVu scans and books to PDF, with resolution, compression and page range options.EML to PDFConvert .eml emails to PDF with sender, recipients, date, formatted body, images and attachments.MOBI to PDFConvert DRM-free MOBI, AZW and AZW3 e-books to PDF with chapters, images and page size options.MSG to PDFConvert Outlook .msg emails to PDF with headers, formatted body, images and attachment list.ODT to PDFConvert OpenDocument Text (.odt) files to PDF with headings, lists, tables and images.EPS to PDFConvert EPS and PostScript files to vector PDF in your browser, cropped to the artwork.PDF to CSVExtract tables from a PDF to CSV files, with draggable column lines to fix the columns.PDF to SVGConvert PDF pages to scalable SVG vector files, with text kept as text or as paths.PDF to WEBPConvert PDF pages to small, sharp WEBP images with a DPI choice and a quality slider.PDF to EPUBConvert PDF to a reflowable EPUB e-book with chapters, headings, images and a table of contents.Scanned PDF to Word (OCR)OCR scanned PDFs or page photos into an editable Word document with rebuilt paragraphs.Word to JPGTurn every page of a Word .docx document into a JPG image, free and in your browser.Cursive Writing WorksheetMake cursive tracing worksheets from any text: joined letters, dotted and faded rows. PDF.EPUB MakerWrite or import chapters, add title, author and cover, and export a valid EPUB 3 e-book.Images to PowerPointTurn photos into a PowerPoint .pptx deck, one image per slide, with captions and 16:9 or 4:3.
See all 53 PDF Converters →