HTML To PDF API avatar
HTML To PDF API

Pricing

from $7.00 / 1,000 results

Go to Apify Store
HTML To PDF API

HTML To PDF API

Developed by

Sachin Kumar Yadav

Sachin Kumar Yadav

Maintained by Community

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.

0.0 (0)

Pricing

from $7.00 / 1,000 results

0

2

1

Last modified

2 days ago

πŸ“„ HTML to PDF Converter - Apify Actor

Convert web pages and HTML content into high-quality PDF documents with ease! πŸš€

Apify Node.js LICENSE

Transform any webpage URL or raw HTML content into professional PDF documents with customizable formatting options. Perfect for generating reports, archiving web content, creating documentation, and automating PDF generation workflows.


πŸ“‘ Table of Contents


✨ Features

FeatureDescription
🌐 URL to PDFConvert any webpage URL directly to PDF
πŸ“ HTML to PDFTransform raw HTML content into PDF documents
🎨 Custom FormattingControl page size, scale, margins, and orientation
πŸ–ΌοΈ Background GraphicsInclude or exclude background colors and images
⏱️ Smart WaitingWait for specific elements or set custom timeouts
πŸ“¦ Batch ProcessingProcess multiple conversions efficiently
πŸ”’ ReliableBuilt on Apify's robust infrastructure

Key Capabilities

  • βœ… Multiple Page Formats: A0-A6, Letter, Legal, Tabloid, Ledger
  • βœ… Scale Control: Adjust rendering scale from 0.1x to 2x
  • βœ… CSS Selector Waiting: Wait for specific elements before conversion
  • βœ… Custom Timeouts: Configure wait times for dynamic content
  • βœ… Background Printing: Include/exclude background graphics
  • βœ… Automatic Naming: Smart file naming with timestamps

πŸš€ Quick Start

Prerequisites

Basic Usage

  1. Navigate to the Actor on Apify platform
  2. Select Conversion Type: Choose "Convert URL to PDF" or "Convert HTML to PDF"
  3. Provide Input:
    • For URL: Enter the webpage URL
    • For HTML: Paste your HTML content
  4. Configure Options (optional): Set page format, scale, wait time, etc.
  5. Run the Actor and download your PDF!

Minimal Example

Convert URL to PDF:

{
"conversionType": "url",
"url": "https://www.example.com"
}

Convert HTML to PDF:

{
"conversionType": "html",
"htmlContent": "<html><body><h1>Hello World!</h1></body></html>"
}

πŸ“‹ Input Parameters

Required Parameters

ParameterTypeDescription
conversionTypestringRequired. Choose "url" or "html"
urlstringRequired if conversionType is "url". Webpage URL to convert
htmlContentstringRequired if conversionType is "html". Raw HTML code to convert

Optional Parameters

ParameterTypeDefaultDescription
pageFormatstring"A4"Page size format (A0-A6, Letter, Legal, etc.)
scalenumber1Rendering scale (0.1 to 2)
printBackgroundbooleantrueInclude background colors and images
waitTimeinteger2500Wait timeout in milliseconds (0-30000)
waitForSelectorstring-CSS selector to wait for before conversion
outputFileNamestring"output.pdf"Name of the output PDF file

πŸ’‘ Usage Examples

Example 1: Convert Website to PDF

Convert a webpage with default settings:

{
"conversionType": "url",
"url": "https://www.example.com",
"outputFileName": "example-page.pdf"
}

Example 2: Convert HTML with Custom Format

Convert HTML content with custom page format and scale:

{
"conversionType": "html",
"htmlContent": "<!DOCTYPE html><html><head><title>My Document</title></head><body><h1>Hello World!</h1></body></html>",
"pageFormat": "Letter",
"scale": 1.2,
"printBackground": true,
"outputFileName": "custom-document.pdf"
}

Example 3: Wait for Dynamic Content

Convert a page after waiting for a specific element:

{
"conversionType": "url",
"url": "https://www.example.com",
"waitForSelector": ".content-loaded",
"waitTime": 5000,
"outputFileName": "dynamic-content.pdf"
}

Example 4: High-Quality PDF with Background

Generate a high-quality PDF with background graphics:

{
"conversionType": "html",
"htmlContent": "<html><body style='background: linear-gradient(45deg, #ff6b6b, #4ecdc4); padding: 50px;'><h1>Beautiful PDF</h1></body></html>",
"pageFormat": "A4",
"scale": 1,
"printBackground": true,
"outputFileName": "beautiful-document.pdf"
}

βš™οΈ Configuration Options

Page Formats

The actor supports the following page formats:

FormatDimensionsUse Case
A0841 Γ— 1189 mmLarge posters
A1594 Γ— 841 mmPosters
A2420 Γ— 594 mmLarge drawings
A3297 Γ— 420 mmDrawings, diagrams
A4210 Γ— 297 mmDefault - Documents, letters
A5148 Γ— 210 mmBooklets, notes
A6105 Γ— 148 mmPostcards, small notes
Letter8.5 Γ— 11 inUS standard documents
Legal8.5 Γ— 14 inLegal documents
Tabloid11 Γ— 17 inNewspapers
Ledger17 Γ— 11 inSpreadsheets

Scale Options

Scale ValueEffect
0.1 - 0.9Smaller output, less detail
1.0Default - Normal size
1.1 - 2.0Larger output, more detail

Wait Configuration

OptionDescriptionRecommended Value
waitTimeTime to wait before conversion (ms)2500 (default) for static pages, 5000+ for dynamic content
waitForSelectorCSS selector to wait forUse for pages with JavaScript-rendered content

πŸ“Š Output Format

The actor returns a structured output with the following information:

Output Structure

{
"processedItems": 1,
"successful": 1,
"failed": 0,
"results": [
{
"fileName": "output.pdf",
"source": "https://www.example.com",
"size": 123456,
"status": "success"
}
]
}

Output Fields

FieldTypeDescription
processedItemsnumberTotal number of items processed
successfulnumberNumber of successful conversions
failednumberNumber of failed conversions
resultsarrayArray of conversion results
results[].fileNamestringName of the generated PDF file
results[].sourcestringSource URL or "htmlContent"
results[].sizenumberPDF file size in bytes
results[].statusstringStatus: "success" or "failed"
results[].errorstringError message (if failed)

Accessing PDF Files

PDF files are stored in the Key-Value Store and can be accessed via:

  • Apify platform UI (Storage β†’ Key-Value Store)
  • Apify API
  • Dataset output (metadata)

πŸ”§ Best Practices

βœ… Do's

  1. Use Appropriate Wait Times

    • Static pages: 2500ms (default)
    • Dynamic/SPA pages: 5000-10000ms
    • Heavy JavaScript pages: 10000-30000ms
  2. Specify CSS Selectors for Dynamic Content

    {
    "waitForSelector": ".main-content",
    "waitTime": 5000
    }
  3. Use Descriptive File Names

    {
    "outputFileName": "monthly-report-2024.pdf"
    }
  4. Enable Background Graphics for Visual Content

    {
    "printBackground": true
    }
  5. Choose Appropriate Page Format

    • Documents: A4 or Letter
    • Presentations: A3 or Tabloid
    • Notes: A5 or A6

❌ Don'ts

  1. Don't Use Very Short Wait Times

    • Avoid: waitTime: 500 for dynamic pages
    • May result in incomplete PDFs
  2. Don't Forget to Specify Conversion Type

    • Always set conversionType explicitly
  3. Don't Use Invalid URLs

    • Ensure URLs are accessible and valid
    • Check for authentication requirements
  4. Don't Overuse Scale

    • Scale > 1.5 may increase file size significantly
    • Scale < 0.5 may reduce readability

❓ Frequently Asked Questions

General Questions

Q: What types of content can I convert?
A: You can convert any accessible webpage URL or raw HTML content. The actor supports static HTML, dynamic JavaScript-rendered pages, and styled content.

Q: How long does conversion take?
A: Conversion time depends on page complexity and wait settings. Simple pages typically convert in 3-5 seconds, while complex pages may take 10-30 seconds.

Q: What is the maximum file size?
A: There's no hard limit, but very large PDFs may take longer to generate. Typical PDFs range from 100KB to 10MB.

Q: Can I convert password-protected pages?
A: The actor can only access publicly available content. Password-protected or authentication-required pages cannot be converted directly.

Technical Questions

Q: What happens if a conversion fails?
A: Failed conversions are included in the output with an error field describing the issue. The failed count is incremented, but the actor continues processing.

Q: How do I handle pages with infinite scrolling?
A: Use waitForSelector to wait for specific content, or set a higher waitTime to allow content to load before conversion.

Q: Can I convert multiple pages in one run?
A: Currently, the actor processes one conversion per run. For multiple pages, run the actor multiple times or use Apify's scheduling features.

Q: Does the actor support custom headers or cookies?
A: The current version uses default browser settings. Custom headers and cookies are not directly supported in the input schema.

Q: What if my page uses iframes?
A: The actor captures the main page content. Iframe content may be included depending on the page structure and security settings.

Formatting Questions

Q: Can I set custom margins?
A: Custom margins are not directly supported in the current version. The actor uses default margins optimized for readability.

Q: How do I create landscape PDFs?
A: Landscape orientation is not directly supported in the current input schema. Use CSS @page rules in your HTML for landscape formatting.

Q: Can I add headers and footers?
A: Headers and footers are not directly supported. You can include them in your HTML content using CSS or HTML elements.

Q: What's the difference between scale and page format?
A: Page format changes the physical page size (A4, Letter, etc.), while scale changes the zoom level of the content (0.1x to 2x).


πŸ“ License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.


🀝 Support

  • Documentation: Check this README for detailed information
  • Issues: Report issues through Apify platform
  • Community: Join Apify community for discussions

Made with ❀️ for the Apify community

Convert HTML to PDF effortlessly with this powerful Apify Actor!

Find me Better

HTML to PDF, Convert HTML pages to a PDF document, HTML to PDF converter online, convert PDF, best html to pdf converter online, free html to pdf api, convert webpage to pdf, html to pdf javascript, html to pdf without watermark.