HTML is the easiest way to lay out a document with your own fonts, colors and tables, and PDF is the format people expect to download, print and attach to an email. This converter joins the two. Paste the markup for an order summary, a price list, a report or a one-page flyer, or point it at a public web page, and it returns a real PDF: text you can select and search, sharp lines at any zoom, and the page size you chose.
The PDF is drawn on our server with Dompdf, an open-source HTML and CSS layout engine written in PHP. It follows the CSS you give it, including print styles and @page rules, but it is not a web browser. The sections below explain what it supports, where it differs from Chrome, and when the browser print option on the same page is the better choice.
How to convert HTML to PDF
- Stay on the Paste HTML tab and paste your markup into the HTML box. A full page with <html>, <head> and <style> works, and so does a fragment such as a single table. Load the sample fills in a wholesale order summary you can edit, and Open an .html file reads a file from your computer.
- Optional: open Extra CSS and add rules. They are applied after the page's own styles, so they win on equal specificity.
- Watch the Live preview. It shows the page at the width of the printable area for the paper size and margins you picked.
- Choose a Page size (A4, Letter, Legal or 4 x 6 in), an Orientation and Margins from None (0 mm) to Wide (25 mm).
- Type a File name, or leave it empty to use the page's <title>.
- Click Convert to PDF. You get a preview of page 1, the page count and the file size, with Download PDF and Open in a new tab buttons.
Your HTML is saved in this browser as you type, so it is still there if you reload the page. It is not saved on our server.
Convert a web page by its address
Switch to the Web page address tab, paste a link such as https://example.com/pricing and click Convert to PDF. Our server downloads the page's HTML, then renders it with the page's own stylesheets and images, resolving relative links against the page address.
Three things decide how well this works:
- JavaScript does not run. The converter reads the HTML the server sends. Pages that build their content in the browser, such as many web apps, some store themes and pages behind a cookie banner, come out empty or partial. For those, open the page in your browser, press Ctrl+P (Cmd+P on a Mac) and choose Save as PDF.
- Print styles apply. The converter uses the print media type, the same as a browser's print dialog. If the site hides its menu or footer when printing, the PDF hides them too.
- Only public pages. The address must be a public site on the normal web ports. Addresses on private networks and HTML pages over 2 MB are refused, and a page behind a login converts as its login screen.
Page sizes, orientation and margins
| Size | Portrait dimensions | Typical use |
|---|---|---|
| A4 | 210 x 297 mm | Invoices and documents outside North America |
| Letter | 8.5 x 11 in (215.9 x 279.4 mm) | US and Canadian documents |
| Legal | 8.5 x 14 in (215.9 x 355.6 mm) | Contracts and long forms |
| 4 x 6 in | 101.6 x 152.4 mm | Shipping and packing labels for thermal printers |
The size, orientation and margins you pick are written into the document as an @page rule placed after all of your CSS, so they take priority over any @page rule already in your HTML. With Normal margins (15 mm) on A4 portrait, the printable width is 180 mm, which is about 680 CSS pixels at 96 per inch. Design to that width and nothing will be cut off.
What CSS works in the PDF
Dompdf handles most of CSS 2.1 and some CSS3. In practice that covers the documents people usually make: text styling, colors, borders, backgrounds, rounded corners, tables, floats and positioned boxes. According to Dompdf's own documentation, it does not support flexbox or grid.
| Feature | In the PDF | What to do instead |
|---|---|---|
| Tables, colspan, rowspan, borders | Supported | Use tables for columns side by side |
| Floats and position: absolute | Supported | |
| page-break-before, page-break-after | Supported | Add style="page-break-before: always" to start a new page |
| @media print and @page | Supported | Page size and margins come from the options above |
| Flexbox and CSS grid | Not supported; items stack | Use a table, or Print with my browser instead |
| Inline <svg> markup | Not supported | Use <img src="https://.../logo.svg"> or a data: URI |
| PNG, JPEG, GIF, BMP images | Supported over https or as data: URIs | Relative paths need the URL mode or a full address |
| Web fonts | @font-face with TTF files over https | Unicode text falls back to DejaVu Sans, which covers most languages written in Latin, Greek and Cyrillic |
| JavaScript | Never runs; <script> tags are removed | Paste the HTML after the script has built it |
Tip: Dompdf cannot split a single table row across two pages. If you have a row with a very long cell, break the content into several rows so the table can flow onto the next page.
Getting a design ready for print
A layout that looks right in a browser window can still print badly, because a page has a fixed width and the screen does not. A few habits make the PDF match what you expect the first time.
- Use print units. Sizes in pt, mm or in map directly to the page: 10pt body text and 1mm borders look the same on every printer. Pixels work too, at 96 per inch, so a 680px wide block fills an A4 page with 15 mm margins.
- Use percentage widths. A table set to
width: 100%fits Letter, A4 and landscape pages without changes. A fixed 900px layout gets cut off on a portrait page. - Keep images light. A 4000 pixel product photo shown at 2 inches wide makes the PDF large without looking better. Resize it first with the image resizer; around 300 pixels per printed inch is plenty.
- Set colors on purpose. Very light gray text and thin hairlines can disappear on office printers. Use at least #6b7280 for secondary text and 1px or thicker borders.
- Name a font that exists. If your CSS asks for a font the engine does not have and you did not load it with @font-face, the text falls back to DejaVu Sans. That keeps every character visible, but the look changes, so check the preview on the result card.
- Control breaks. Put
page-break-inside: avoidon small boxes such as an address block or a totals table, and a page break before each new section of a long report.
When to use Print with my browser instead
The Print with my browser instead button sends your pasted HTML to your own browser's print dialog through a hidden frame, with the same page size and margins, and with scripts disabled. Choose Save as PDF as the destination. Use it when:
- your layout depends on flexbox or grid,
- you need a font your browser has but that is not available as a TTF file online,
- you have used today's free server conversions.
The browser's PDF is also vector and searchable. The differences are that the result depends on your browser version, you need to turn off the headers and footers option in the print dialog for a clean page, and background colors print because the converter asks the browser to keep exact colors.
Example: a wholesale order summary
The built-in sample is a one-page order summary with a heading, a shipping box and a four-column table: three product lines of 24 x $18.50 = $444.00, 48 x $6.25 = $300.00 and 36 x $7.40 = $266.40, and a bold total of $1,010.40. It uses only table layout, borders and background colors, so the PDF matches the preview. On A4 with Normal margins it converts to a single page of about 25 KB. Try switching to Letter and Landscape: the table gets wider, the page count stays at one, and nothing else in the HTML needs to change.
If you build documents like this from data, such as invoices from an order export, the JSON to PDF template generator fills the HTML for you from JSON and then uses the same PDF engine. For a ready-made store invoice, the Shopify invoice generator is quicker.
Common uses in a store
Most online sellers already have HTML they want as a PDF, even if they do not think of it that way:
- Line sheets and price lists for wholesale buyers, built as a table of products with prices and minimum order quantities.
- Order confirmations and packing slips copied from an email template, so a warehouse can print them.
- Size charts and care guides from a product page, saved as a PDF to include in the box or attach to a marketplace listing.
- Policy pages such as returns and shipping terms, for B2B customers who ask for a signed copy. Our refund policy generator writes the text; this tool turns it into a PDF.
- Reports exported from a dashboard as HTML, turned into a file you can send to a partner who will not log in.
Limits and privacy
- HTML up to 2 MB and extra CSS up to 500 KB. Embedded base64 images count toward the 2 MB, so link large images by https address instead.
- Up to 8,000 HTML elements per document, which is roughly 60 pages of a large table. Bigger documents are refused with a message rather than timing out.
- Linked images, stylesheets and fonts load only over https, only from public addresses, with a 6 second timeout each, no redirects, and at most 40 files per document. Files that are skipped are counted on the result card.
- There is a daily limit of free conversions per visitor. When you reach it, the tool tells you, and browser printing still works.
- Your HTML is sent to our server only to build the PDF. It is not saved, logged or shared, and the PDF is returned straight to your browser.
Once you have the PDF, you can join it with other files in Merge PDF or shrink it with Compress PDF, both of which run in your browser.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Columns stack on top of each other | Flexbox or grid layout | Rebuild the columns as a table, or use browser print |
| Images are missing | Relative path, http address, or a private host | Use a full https address or a data: URI |
| Text shows as boxes | The font lacks those characters | Set font-family: DejaVu Sans or load a TTF that has them |
| A web page converts empty | Its content is drawn by JavaScript | Print it from your browser instead |
| Content is cut off at the right | Fixed widths wider than the printable area | Use percentage widths or Narrow margins |
| A table row jumps to the next page | Rows cannot split across pages | Split long cells into several rows |