# HTML to PDF (Precise Layout)

Render HTML/CSS to a PDF with precise headers, footers, and print settings

> Canonical page: https://elysiatools.com/en/tools/html-to-pdf-precise

- **Category:** Document Tools

- **Keywords:** pdf, html, css, print, header, footer, puppeteer, layout, 精准, 页眉, 页脚

## Overview

This tool renders HTML/CSS to PDF using a headless browser for high-fidelity layout. \*\*Header & Footer:\*\* - Provide custom HTML templates for headers/footers - Use \`\` and \`\` for page numbers - CSS in header/footer is supported with inline styles \*\*Print Options:\*\* - A4/Letter/Legal page sizes - Margin control (mm) - Print background and scaling - CSS \`@page\` and \`@media print\` support (enable "Prefer CSS Page Size")

## Inputs

- **HTML Content** (textarea): # Hello PDF Write your HTML here...
- **Custom CSS** (textarea): /* Optional custom styles */
- **Page Size** (select)
- **Landscape** (checkbox)
- **Print Background** (checkbox)
- **Scale** (number)
- **Margin Top (mm)** (number)
- **Margin Bottom (mm)** (number)
- **Margin Left (mm)** (number)
- **Margin Right (mm)** (number)
- **Header Template (HTML)** (textarea)
- **Footer Template (HTML)** (textarea)
- **Media Type** (select)
- **Wait Until** (select)
- **Extra Wait Time (ms)** (number)
- **Prefer CSS Page Size** (checkbox)

## When to use

- When you need to generate PDFs from web-based content with exact layout preservation.
- When custom headers and footers, such as dynamic page numbers or logos, are required.
- When specific print configurations like page size, margins, and background printing must be applied.

## How it works

- Input your HTML content and optional custom CSS for styling.
- Configure page settings such as size, orientation, margins, and scale.
- Define header and footer templates using HTML with placeholders for page numbers.
- The tool renders the content in a headless browser and outputs a PDF file.

## Use cases

- Generating invoices or receipts with company branding and automatic page numbers.
- Creating printable reports from web dashboards with consistent headers and footers.
- Producing manuals or guides with precise layout and custom print settings.

## Frequently asked questions

### What page sizes are supported?

A4, Letter, Legal, and A5.

### How do I add page numbers to the PDF?

Use and in your header or footer HTML template.

### Can I use CSS for print-specific styling?

Yes, you can add custom CSS and enable 'Prefer CSS Page Size' to use @page rules.

### What is the 'Wait Until' option for?

It controls when the page is considered loaded, such as waiting for network activity to finish.

### How can I adjust the PDF scaling?

Use the Scale option to set a value between 0.5 and 2, with 1 as the default.

## Related tools

- [HTML to PDF Renderer](https://elysiatools.com/en/tools/html-to-pdf-renderer): Render a limited HTML subset into a PDF with a deterministic layout
- [HTML Mail to PDF](https://elysiatools.com/en/tools/libreoffice-html-mail-to-pdf): Render email HTML content to PDF with preserved basic formatting using Puppeteer
- [PDF Header/Footer Snippets](https://elysiatools.com/en/tools/pdf-header-footer-snippets): Convert HTML to PDF with reusable logo, title, and date snippets
- [PDF Invoice Generator](https://elysiatools.com/en/tools/pdf-invoice-generator): Generate a branded invoice PDF from structured line items
- [PDF Page Numbering Styles](https://elysiatools.com/en/tools/pdf-page-numbering-styles): Convert HTML to PDF with Roman, Arabic, or chapter-prefixed page numbers
- [PDF Table Layout Engine](https://elysiatools.com/en/tools/pdf-table-layout-engine): Render structured table data into a paginated PDF with repeating headers and zebra rows
- [PDF to HTML](https://elysiatools.com/en/tools/pdf-to-html): Convert PDF documents to HTML web pages with preserved formatting and structure
- [PDF Table Extractor to CSV/JSON](https://elysiatools.com/en/tools/pdf-table-extractor-to-csv-json): Extract tables from PDFs with OpenDataLoader and export them as structured JSON, flat CSV, or HTML tables

## Samples

- [PDF Samples](https://elysiatools.com/en/samples/pdf-samples): Generated PDF samples from tools dated 2026-02-01 to 2026-02-10
- [Markdown Slide Deck Samples](https://elysiatools.com/en/samples/md-slide-deck-to-pdf): Remark/Marp style Markdown slide decks for testing PDF export layouts
- [HTML Viewer Samples](https://elysiatools.com/en/samples/html-viewer-samples): Sample HTML files (semantic page, form, landing page) for the in-browser HTML Viewer
- [HTML with Images Samples](https://elysiatools.com/en/samples/html-with-images): HTML source code samples with images for testing extraction

## Related content

- [HTML Content Extraction, Cleanup, and Delivery](https://elysiatools.com/en/hubs/html-content-extraction-cleanup-and-delivery): Extract links, images, attributes, and tables from HTML, remove unwanted markup, and ship verified Markdown, PDF, or CSV outputs.
- [Print-Ready PDF Layout Workflows](https://elysiatools.com/en/hubs/print-pdf-layout-workflows): Convert HTML, Markdown, README, or plain text into polished PDFs with page templates, typography, headers, footers, numbering, TOC, columns, and direction checks.
- [HTML Email Review and PDF Delivery](https://elysiatools.com/en/hubs/html-convert): Inspect HTML email metadata, review fragile attributes and image references, create a reviewer-safe fallback copy, and render a shareable PDF proof.
