📄 File and Document Free Forever

HTML to PDF Converter

Turn raw HTML markup into a paginated PDF with a live preview, custom margins, headers, footers, and page numbers. Renders your HTML safely in a sandboxed frame before conversion. This HTML to PDF converter is free and needs no signup.

HTML Source
Live Preview
Page Settings
About This Tool

Why this converter renders your HTML in a hidden iframe before capturing it

Turning arbitrary HTML into a PDF is really a two step trick: paint the markup exactly as a browser would render it, then photograph that rendered layout and lay the photograph into a PDF page. This HTML to PDF converter does the painting in a sandboxed iframe with its own document, and does the photographing with html2canvas, then slices that image into PDF pages with jsPDF, moving each page cut into a blank gap so lines of text are not split. Both steps run in your browser. The HTML you paste or upload never leaves the page.

Why an iframe, specifically

An earlier version of this approach captured content sitting directly on the main page and produced blank PDFs. html2canvas renders the entire page and then crops down to your target element's bounding box, a documented behavior of the library. The fix was to build a completely isolated iframe with its own srcdoc document containing only the HTML being converted, positioned at true document coordinate (0,0) with position:absolute rather than position:fixed, and to force window.scrollTo(0,0) right before capture so the crop always lands in the right place regardless of how far down the page the visitor had scrolled.

Step 1 Build the render frame A hidden iframe is created, sandboxed with allow-same-origin, and loaded with your HTML via srcdoc. An opaque overlay covers it so you never see the raw unstyled flash.
Step 2 Wait for images Every <img> inside the rendered document is checked for .complete, and the tool waits for load or error events on any that are not finished, capped at a 4 second timeout so one dead image link cannot hang the conversion indefinitely.
Step 3 Capture and build the PDF html2canvas rasterizes the iframe body at your chosen scale factor, and jsPDF places it on pages sized to your selected format and orientation. Cuts land in white space between lines, and CSS page-break-before or break-before: page starts a new page.
Step 4 Draw header, footer, page numbers After the visual capture, the tool loops over every generated page and adds header text, footer text, and "Page X of Y" numbering. Page numbers are real PDF text, and header and footer text is drawn at high resolution so accented letters and non-Latin scripts print correctly.
// render frame positioning, from the tool source renderFrame.style.position = 'absolute'; renderFrame.style.top = '0'; renderFrame.style.left = '0'; window.scrollTo(0, 0); renderFrame.srcdoc = html; // ... var opts = { image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: scale, useCORS: true, backgroundColor: '#ffffff' }, jsPDF: { unit: 'in', format: pageSize, orientation: orientation } };

Options and their effect on the raster capture

OptionWhat it changes
Scalehtml2canvas's device pixel multiplier; higher scale means a sharper but larger capture
BackgroundPrints or drops background colors and images, like the matching option in a browser print dialog
MarginNone, normal (0.5in) or wide (1in), applied as jsPDF page margin around the image
Allow scriptsAdds allow-scripts to the iframe sandbox, letting pasted JavaScript run before capture
Page numbersDraws real vector text via jsPDF, independent of the rasterized content
Complex CSS layouts and blocked cross-origin stylesheets can still fail. html2canvas approximates CSS rendering rather than using the browser's actual paint pipeline for the capture, so advanced layout features and any external stylesheet blocked by CORS can render incorrectly or not at all, which is why the tool's own error message names both as known limitations rather than claiming universal fidelity.

Live preview

A separate sandboxed iframe mirrors your input as you type, debounced by 350ms, so you can check the markup before spending time on a full conversion.

File upload

An .html file can be loaded directly with FileReader.readAsText(), populating the same textarea the paste option uses.

html2canvas rasterization jsPDF page assembly Sandboxed srcdoc iframe Header, footer, page numbers

Rendering engines and specs

Documents people generate this way

Archiving an email template or landing page as a fixed document, generating a printable invoice from a small HTML snippet, converting an internal report built as an HTML fragment into something you can attach to an email, or producing a quick PDF preview of a web component during development without setting up a headless browser toolchain.

Common Questions

FAQ: HTML to PDF Converter

No. Browsers do not let one website read the pages of another, so there is no URL option. Open the page, view its source (Ctrl + U in most browsers) or save it as an .html file, then paste or upload it here. Images and stylesheets only load if their addresses are full https links.

Yes. Both inline styles and style tags included in your HTML render exactly as a browser would display them, since the conversion uses an actual browser rendering pass rather than a simplified parser.

Yes. Enter text in the Header Text and Footer Text fields in Page Settings, and leave Add Page Numbers checked. All three are stamped onto every page of the resulting PDF.

Your markup is rendered inside a sandboxed iframe with scripting restricted, so the HTML to PDF converter focuses purely on visual layout, fonts, colors, and structure, rather than running arbitrary code.

No. Rendering and PDF generation both happen locally in your browser. Only images or stylesheets your HTML links to are fetched, by your own browser, from wherever they are hosted.