HTML To PDF API
Pricing
from $5.00 / 1,000 results
HTML To PDF API
Convert HTML content and webpage URLs to high-quality PDF documents instantly. HTML to PDF converter with customizable page formats (A4, Letter), scale control, background graphics, and smart waiting for dynamic content. Perfect for reports, documentation, and automated PDF generation workflows.
Pricing
from $5.00 / 1,000 results
Rating
0.0
(0)
Developer
Sachin Kumar Yadav
Maintained by CommunityActor stats
1
Bookmarked
52
Total users
0
Monthly active users
14 days ago
Last modified
Categories
Share
📄 HTML to PDF Converter – Fast & Reliable Web & HTML to PDF Generation
🚀 Convert any HTML content, invoice, receipt, report, or live webpage URL into high-quality, pixel-perfect PDF documents using headless Chrome rendering. Complete with custom paper sizes, margins, headers, footers with page numbers, CSS backgrounds, and direct download links. Built with Apify best practices for reliability, speed, and scale.
📋 Table of Contents
- ✨ Features
- 🎯 Use Cases
- ⚡ Quick Start
- 📊 Input Parameters
- 📤 Output Format
- ❓ FAQ
- 🛠️ Troubleshooting
- 🏷️ Tags
- 🚀 Get Started Now
✨ Features
- HTML to PDF – Convert raw HTML code into professional, print-ready PDF files
- URL to PDF – Render live web pages and articles directly from any public URL
- Full Styling Support – Supports inline
<style>, external CSS stylesheets, web fonts (Google Fonts), and images - Custom Paper Formats – Choose from A3, A4, A5, Letter, Legal, or Tabloid
- Orientation & Margins – Portrait or landscape layout with customizable CSS unit margins (mm, in, px)
- Headers & Footers – Add custom running headers and footers with dynamic page numbers (
pageNumber/totalPages) - Background Graphics – Full control over CSS background colors, gradients, and background images
- Rendering Scale – Fine-tune scale factor from 0.1x to 2x for optimal fit
- Page Ranges – Print specific pages or page selections (e.g.,
1-3, 5) - Direct Cloud Storage – PDFs are automatically saved to Apify Key-Value Store with instant public download URLs
🎯 Use Cases
| Use Case | Description | Key Benefits |
|---|---|---|
| Automated Invoicing & Billing | Generate invoices, receipts, and order confirmations dynamically from HTML templates | Pixel-perfect invoices, automated accounting workflows |
| Webpage Archiving & Snapshots | Save blog posts, news articles, and documentation as offline PDF files | Permanent archival, reading offline, compliance records |
| Reports & Dashboard Exports | Turn business dashboards, charts, and metrics tables into executive reports | Clean page layouts, consistent corporate branding |
| Contracts & Legal Documents | Render NDAs, agreements, and certificates from dynamic customer data | Consistent pagination, legal page numbering |
| Ticket & Boarding Pass Generation | Create event tickets, badges, and vouchers with scannable barcodes & QR codes | High print resolution, exact dimension control |
| Web Scraping to PDF | Archive scraped web pages or search results in PDF format for research | Seamless integration into Apify scraping pipelines |
⚡ Quick Start
1. Basic – HTML to PDF
{"html": "<h1 style=\"font-family: Arial; color: #2563eb;\">Invoice #INV-2026-001</h1><p>Amount Due: <strong>$1,250.00</strong></p>","filename": "invoice-001","format": "A4"}
2. Live Webpage – URL to PDF
{"url": "https://example.com","filename": "example-page","format": "Letter","orientation": "landscape"}
3. Professional Report – Custom Margins & Page Numbers
{"html": "<div style=\"font-family: sans-serif; padding: 20px;\"><h1>Annual Business Report</h1><p>Confidential summary for stakeholders...</p></div>","filename": "annual-report","format": "A4","marginTop": "25mm","marginBottom": "25mm","displayHeaderFooter": true,"headerTemplate": "<div style=\"font-size: 9px; width: 100%; text-align: center; color: #666;\">Acme Corp – Confidential</div>","footerTemplate": "<div style=\"font-size: 9px; width: 100%; text-align: center; color: #666;\">Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div>"}
📊 Input Parameters
| Parameter | Type | Default | Description | Example |
|---|---|---|---|---|
html | String | — | Raw HTML document string to render (Max 5 MB) | "<h1 style='color:blue'>Hello</h1>" |
url | String | — | Live public webpage URL to render into PDF | "https://en.wikipedia.org/wiki/PDF" |
filename | String | "document" | Name of the output PDF file (without .pdf extension) | "monthly_invoice" |
format | String | "A4" | Standard paper size (A3, A4, A5, Letter, Legal, Tabloid) | "A4", "Letter" |
orientation | String | "portrait" | Page orientation (portrait or landscape) | "portrait", "landscape" |
marginTop | String | "15mm" | Top page margin with CSS units (mm, in, px) | "20mm", "0.5in" |
marginRight | String | "15mm" | Right page margin with CSS units | "15mm", "20px" |
marginBottom | String | "15mm" | Bottom page margin with CSS units | "20mm", "0.5in" |
marginLeft | String | "15mm" | Left page margin with CSS units | "15mm", "20px" |
printBackground | Boolean | true | Include CSS backgrounds, gradients, and images | true, false |
scale | Number | 1 | Zoom scale factor between 0.1 and 2 | 1, 0.85 |
displayHeaderFooter | Boolean | false | Enable running headers and footers on every page | true, false |
headerTemplate | String | — | HTML template for top header (must include inline font-size) | "<div style='font-size:8px'>Header</div>" |
footerTemplate | String | — | HTML template for bottom footer (supports pageNumber & totalPages) | "<div style='font-size:8px'><span class='pageNumber'></span></div>" |
pageRanges | String | — | Print specific pages only (e.g., 1-3,5) | "1-5", "2,4,6" |
emulateMedia | String | "print" | CSS media type emulation (print or screen) | "print", "screen" |
waitUntil | String | "load" | Readiness event (load, domcontentloaded, networkidle0, networkidle2) | "networkidle2" |
timeout | Integer | 30000 | Maximum rendering wait time in ms (1,000 to 60,000) | 30000, 45000 |
ℹ️ Note: Provide either
htmlORurl. If both are provided,htmltakes priority.
📤 Output Format
Dataset Record Example
{"source": "html_to_pdf_converter","input_type": "html","input_source": "HTML (327 chars)","filename": "hello.pdf","pdf_download_url": "https://api.apify.com/v2/key-value-stores/0e31f5e3-5889-4605-a15a-7bf916b0e4fd/records/hello.pdf","pdf_key_value_store_key": "hello.pdf","key_value_store_id": "0e31f5e3-5889-4605-a15a-7bf916b0e4fd","file_size_bytes": 31569,"file_size_kb": 30.83,"format": "A4","orientation": "portrait","margins": {"top": "15mm","right": "15mm","bottom": "15mm","left": "15mm"},"print_background": true,"scale": 1,"display_header_footer": false,"page_ranges": "all","emulate_media": "print","wait_until": "load","status": "success","converted_at": "2026-10-20T14:40:43.000Z"}
Output Fields Explained
| Field | Type | Description |
|---|---|---|
filename | String | Generated PDF filename with extension |
pdf_download_url | String | Direct public download URL to access the PDF |
file_size_kb | Number | Generated PDF file size in kilobytes |
file_size_bytes | Integer | Generated PDF file size in bytes |
input_type | String | Input format used (html or url) |
format | String | Paper size used for conversion |
orientation | String | Orientation layout (portrait or landscape) |
status | String | Execution status (success or error) |
converted_at | String | ISO 8601 timestamp of conversion completion |
❓ FAQ
-
Q: Where is my generated PDF saved?
- Your PDF is automatically stored in the run's default Apify Key-Value Store. A direct
pdf_download_urlis returned in the dataset for instant access and downloading.
- Your PDF is automatically stored in the run's default Apify Key-Value Store. A direct
-
Q: Can I use CSS frameworks, Google Fonts, and images?
- Yes! You can include
<link>tags for external fonts (like Google Fonts),<style>tags with custom CSS, Tailwind/Bootstrap via CDN, and<img>tags pointing to public URLs or base64 data URIs.
- Yes! You can include
-
Q: How do page numbers work in headers and footers?
- Enable
displayHeaderFooter: trueand use Chrome's built-in CSS classes in your template:<span class="pageNumber"></span>for current page number<span class="totalPages"></span>for total pages count<span class="date"></span>for formatted date
- Tip: Set top and bottom margins to at least 20mm so headers and footers are not clipped.
- Enable
-
Q: What is the maximum HTML file size supported?
- The API supports raw HTML payloads up to 5 MB, which is ample for hundreds of pages of formatted text and styling.
-
Q: When should I change
waitUntiltonetworkidle0ornetworkidle2?- If your webpage loads external fonts, analytics, or dynamic images via JavaScript, choose
networkidle0ornetworkidle2to ensure all assets finish downloading before rendering.
- If your webpage loads external fonts, analytics, or dynamic images via JavaScript, choose
-
Q: Can I integrate this with other Apify Actors or webhooks?
- Absolutely. You can call this Actor via Apify API, integrate it in Apify Workflows, or use webhooks to automatically download PDFs upon completion into Google Drive, S3, or Zapier.
🛠️ Troubleshooting
| Issue | Cause | Solution |
|---|---|---|
| "No input provided" | Neither html nor url was passed | Provide either raw HTML content or a public webpage URL |
| Header/Footer is cut off | Margins are smaller than the header/footer height | Increase marginTop or marginBottom to 20mm or 25mm |
| Font size too large/small in header | Header/footer templates render outside the main document | Use explicit inline styling like style="font-size: 9px;" |
| Background colors missing | CSS background printing is turned off | Ensure printBackground is set to true |
| Page render timed out (504) | Webpage has heavy media or slow external scripts | Increase timeout (up to 60000 ms) or switch waitUntil to domcontentloaded |
| 413 Payload Too Large | HTML string exceeds 5 MB | Optimize inline SVGs/images or load them via external URLs |
🏷️ Tags
html to pdf, pdf converter, webpage to pdf, url to pdf, chrome pdf generator, html2pdf, headless chrome pdf, puppeteer pdf, invoice generator, receipt to pdf, document generator, pdf api, apify actor, pdf download, automated pdf, print stylesheet
🚀 Get Started Now
Ready to convert HTML or URLs to PDF?
- Provide your HTML content or enter a webpage URL
- Choose your preferred paper size, orientation, and margins
- Click Start to run the actor
- Download your generated PDF directly via the download URL
- Click "Try for free" to test the actor
If this actor helps your workflow, please give it a star!
Built with Apify Platform