HTML To PDF API avatar

HTML To PDF API

Pricing

from $5.00 / 1,000 results

Go to Apify Store
HTML To PDF API

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

Sachin Kumar Yadav

Maintained by Community

Actor stats

1

Bookmarked

52

Total users

0

Monthly active users

14 days ago

Last modified

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

  • 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 CaseDescriptionKey Benefits
Automated Invoicing & BillingGenerate invoices, receipts, and order confirmations dynamically from HTML templatesPixel-perfect invoices, automated accounting workflows
Webpage Archiving & SnapshotsSave blog posts, news articles, and documentation as offline PDF filesPermanent archival, reading offline, compliance records
Reports & Dashboard ExportsTurn business dashboards, charts, and metrics tables into executive reportsClean page layouts, consistent corporate branding
Contracts & Legal DocumentsRender NDAs, agreements, and certificates from dynamic customer dataConsistent pagination, legal page numbering
Ticket & Boarding Pass GenerationCreate event tickets, badges, and vouchers with scannable barcodes & QR codesHigh print resolution, exact dimension control
Web Scraping to PDFArchive scraped web pages or search results in PDF format for researchSeamless 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

ParameterTypeDefaultDescriptionExample
htmlString—Raw HTML document string to render (Max 5 MB)"<h1 style='color:blue'>Hello</h1>"
urlString—Live public webpage URL to render into PDF"https://en.wikipedia.org/wiki/PDF"
filenameString"document"Name of the output PDF file (without .pdf extension)"monthly_invoice"
formatString"A4"Standard paper size (A3, A4, A5, Letter, Legal, Tabloid)"A4", "Letter"
orientationString"portrait"Page orientation (portrait or landscape)"portrait", "landscape"
marginTopString"15mm"Top page margin with CSS units (mm, in, px)"20mm", "0.5in"
marginRightString"15mm"Right page margin with CSS units"15mm", "20px"
marginBottomString"15mm"Bottom page margin with CSS units"20mm", "0.5in"
marginLeftString"15mm"Left page margin with CSS units"15mm", "20px"
printBackgroundBooleantrueInclude CSS backgrounds, gradients, and imagestrue, false
scaleNumber1Zoom scale factor between 0.1 and 21, 0.85
displayHeaderFooterBooleanfalseEnable running headers and footers on every pagetrue, false
headerTemplateString—HTML template for top header (must include inline font-size)"<div style='font-size:8px'>Header</div>"
footerTemplateString—HTML template for bottom footer (supports pageNumber & totalPages)"<div style='font-size:8px'><span class='pageNumber'></span></div>"
pageRangesString—Print specific pages only (e.g., 1-3,5)"1-5", "2,4,6"
emulateMediaString"print"CSS media type emulation (print or screen)"print", "screen"
waitUntilString"load"Readiness event (load, domcontentloaded, networkidle0, networkidle2)"networkidle2"
timeoutInteger30000Maximum rendering wait time in ms (1,000 to 60,000)30000, 45000

ℹ️ Note: Provide either html OR url. If both are provided, html takes 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

FieldTypeDescription
filenameStringGenerated PDF filename with extension
pdf_download_urlStringDirect public download URL to access the PDF
file_size_kbNumberGenerated PDF file size in kilobytes
file_size_bytesIntegerGenerated PDF file size in bytes
input_typeStringInput format used (html or url)
formatStringPaper size used for conversion
orientationStringOrientation layout (portrait or landscape)
statusStringExecution status (success or error)
converted_atStringISO 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_url is returned in the dataset for instant access and downloading.
  • 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.
  • Q: How do page numbers work in headers and footers?

    • Enable displayHeaderFooter: true and 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.
  • 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 waitUntil to networkidle0 or networkidle2?

    • If your webpage loads external fonts, analytics, or dynamic images via JavaScript, choose networkidle0 or networkidle2 to ensure all assets finish downloading before rendering.
  • 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

IssueCauseSolution
"No input provided"Neither html nor url was passedProvide either raw HTML content or a public webpage URL
Header/Footer is cut offMargins are smaller than the header/footer heightIncrease marginTop or marginBottom to 20mm or 25mm
Font size too large/small in headerHeader/footer templates render outside the main documentUse explicit inline styling like style="font-size: 9px;"
Background colors missingCSS background printing is turned offEnsure printBackground is set to true
Page render timed out (504)Webpage has heavy media or slow external scriptsIncrease timeout (up to 60000 ms) or switch waitUntil to domcontentloaded
413 Payload Too LargeHTML string exceeds 5 MBOptimize 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?

  1. Provide your HTML content or enter a webpage URL
  2. Choose your preferred paper size, orientation, and margins
  3. Click Start to run the actor
  4. Download your generated PDF directly via the download URL
  5. Click "Try for free" to test the actor

If this actor helps your workflow, please give it a star!


Built with Apify Platform