HTML To PDF API
Pricing
from $7.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.
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! π
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
- π Quick Start
- π Input Parameters
- π‘ Usage Examples
- βοΈ Configuration Options
- π Output Format
- π§ Best Practices
- β Frequently Asked Questions
- π License
β¨ Features
| Feature | Description |
|---|---|
| π URL to PDF | Convert any webpage URL directly to PDF |
| π HTML to PDF | Transform raw HTML content into PDF documents |
| π¨ Custom Formatting | Control page size, scale, margins, and orientation |
| πΌοΈ Background Graphics | Include or exclude background colors and images |
| β±οΈ Smart Waiting | Wait for specific elements or set custom timeouts |
| π¦ Batch Processing | Process multiple conversions efficiently |
| π Reliable | Built 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
- Apify account (Sign up for free)
- Basic understanding of JSON input format
Basic Usage
- Navigate to the Actor on Apify platform
- Select Conversion Type: Choose "Convert URL to PDF" or "Convert HTML to PDF"
- Provide Input:
- For URL: Enter the webpage URL
- For HTML: Paste your HTML content
- Configure Options (optional): Set page format, scale, wait time, etc.
- 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
| Parameter | Type | Description |
|---|---|---|
conversionType | string | Required. Choose "url" or "html" |
url | string | Required if conversionType is "url". Webpage URL to convert |
htmlContent | string | Required if conversionType is "html". Raw HTML code to convert |
Optional Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
pageFormat | string | "A4" | Page size format (A0-A6, Letter, Legal, etc.) |
scale | number | 1 | Rendering scale (0.1 to 2) |
printBackground | boolean | true | Include background colors and images |
waitTime | integer | 2500 | Wait timeout in milliseconds (0-30000) |
waitForSelector | string | - | CSS selector to wait for before conversion |
outputFileName | string | "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:
| Format | Dimensions | Use Case |
|---|---|---|
| A0 | 841 Γ 1189 mm | Large posters |
| A1 | 594 Γ 841 mm | Posters |
| A2 | 420 Γ 594 mm | Large drawings |
| A3 | 297 Γ 420 mm | Drawings, diagrams |
| A4 | 210 Γ 297 mm | Default - Documents, letters |
| A5 | 148 Γ 210 mm | Booklets, notes |
| A6 | 105 Γ 148 mm | Postcards, small notes |
| Letter | 8.5 Γ 11 in | US standard documents |
| Legal | 8.5 Γ 14 in | Legal documents |
| Tabloid | 11 Γ 17 in | Newspapers |
| Ledger | 17 Γ 11 in | Spreadsheets |
Scale Options
| Scale Value | Effect |
|---|---|
| 0.1 - 0.9 | Smaller output, less detail |
| 1.0 | Default - Normal size |
| 1.1 - 2.0 | Larger output, more detail |
Wait Configuration
| Option | Description | Recommended Value |
|---|---|---|
waitTime | Time to wait before conversion (ms) | 2500 (default) for static pages, 5000+ for dynamic content |
waitForSelector | CSS selector to wait for | Use 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
| Field | Type | Description |
|---|---|---|
processedItems | number | Total number of items processed |
successful | number | Number of successful conversions |
failed | number | Number of failed conversions |
results | array | Array of conversion results |
results[].fileName | string | Name of the generated PDF file |
results[].source | string | Source URL or "htmlContent" |
results[].size | number | PDF file size in bytes |
results[].status | string | Status: "success" or "failed" |
results[].error | string | Error 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
-
Use Appropriate Wait Times
- Static pages: 2500ms (default)
- Dynamic/SPA pages: 5000-10000ms
- Heavy JavaScript pages: 10000-30000ms
-
Specify CSS Selectors for Dynamic Content
{"waitForSelector": ".main-content","waitTime": 5000} -
Use Descriptive File Names
{"outputFileName": "monthly-report-2024.pdf"} -
Enable Background Graphics for Visual Content
{"printBackground": true} -
Choose Appropriate Page Format
- Documents: A4 or Letter
- Presentations: A3 or Tabloid
- Notes: A5 or A6
β Don'ts
-
Don't Use Very Short Wait Times
- Avoid:
waitTime: 500for dynamic pages - May result in incomplete PDFs
- Avoid:
-
Don't Forget to Specify Conversion Type
- Always set
conversionTypeexplicitly
- Always set
-
Don't Use Invalid URLs
- Ensure URLs are accessible and valid
- Check for authentication requirements
-
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.
