Tech Seekers PDF logoTech Seekers PDF

Blog

Convert HTML to PDF in Your Browser

Published 2026-11-04 · Updated 2026-11-28 · By Tech Seekers

An invoice in HTML form needs to reach the client as a PDF. Converting HTML to PDF in your browser keeps the layout, with honest limits on pictures.

An invoice template sits in your browser as HTML, and the client wants a PDF, not a link. Copying the page into a document breaks the layout, and screenshots cut it into pieces. Turning the HTML itself into a PDF keeps the page as it was designed, with the headings, tables and spacing in place, and it takes about a minute.

The HTML to PDF tool renders your HTML at A4 width and slices it into A4 pages. Paste HTML or upload an .html file, convert, and download a multi-page PDF. Inline styles carry over, so what you styled is what the PDF gets. The render uses Arial at 16 pixels with a line height of 1.5, on a page 794 pixels wide, sliced into pages 1123 pixels tall. That fixed width is why a page designed for a phone screen and a page designed for a desktop both land on the same A4 shape.

Two hard numbers shape what you can convert. HTML over 2 MB is refused, and documents up to about 14 pages render in one go. The page cap follows from the height cap: the tallest canvas the tool will build is 16,384 pixels, and 16,384 divided by 1123 gives 14 pages. A longer document needs splitting at a heading first, then each part converts on its own. If your HTML is close to the limit, split it before you start, not after the tool refuses it. The 2 MB limit is set in src/lib/html-pdf.ts as MAX_HTML_BYTES, and the same file strips scripts and linked stylesheets before rendering.

Each page in the result is a picture of your HTML, so the text is not selectable or searchable in the PDF. That is the biggest limit, and it decides whether this tool fits the job. If the client needs to copy text out of the PDF, search it, or paste a line into an email, this is the wrong tool for that job. If the client only needs to read it, print it, or file it, a picture of the page is exactly what they need.

Pictures and fonts are the next thing to plan around. Pictures hosted on other sites usually come out blank unless that host lets other pages read them, and web fonts fall back to a plain system font. Embedding pictures in the HTML itself fixes the first problem every time, because a data URI image travels with the document instead of being fetched from elsewhere. A logo saved as a data URI renders, while the same logo linked from another site often does not. Test the images on page one before you convert a long document.

Scripts and linked stylesheets are stripped before rendering, so script tags never run during the render. That stripping step is in src/lib/html-pdf.ts. Inline style blocks are kept, wherever they appear, and full document wrappers are dropped, so a fragment and a full document render the same way. That means you can paste a snippet of HTML with its own style block and get a clean page, without building a whole page around it. Keep the styling inline and simple, and the render will follow it.

Test with one page before you convert a long document. A layout problem on page one will repeat on every page, and catching it early saves a dozen re-renders. Build a short version first, with the heading, one table, and one image, convert it, and open the PDF. Check the heading size, the table borders, and whether the image rendered at all. If that page is right, the full document will follow the same rules, and you can convert the rest with confidence.

Page breaks are the part people notice last. The tool slices the rendered page into fixed height chunks, so a table row or a heading can land across a page break if it sits in the wrong spot. There is no setting to keep a block together, so the fix is to look at the result and adjust the HTML. Add space before a heading that keeps landing at the bottom of a page, or shorten a table so it ends before the break. A quick look at the PDF after each change is faster than guessing.

If the conversion fails, the message tells you why, and the fix is usually plain. Empty HTML gives an error asking for content, so paste the HTML first. HTML over 2 MB gives an error asking you to split it, so split at a heading. A document over about 14 pages gives an error about the height, so split it into parts. HTML that will not render at all gives an error asking for simpler HTML with inline styles, so strip the fancy parts and try again.

File the original HTML away after you convert. The PDF is a picture of the page, and you cannot edit the words inside it, so any change means editing the HTML and converting again. Save the HTML next to the PDF with the same name, so the two stay together, and the next edit takes a minute instead of a rebuild. That pair, HTML as the source and PDF as the copy you send, is the habit that makes this tool useful instead of frustrating.

Two sources sit behind the details here. The html2canvas project documents how a page is drawn to a canvas, and the MDN page on HTML covers the markup itself. Both are worth a look if you want to know why a rendered PDF behaves so differently from a typed one.

Try it yourself