HTML To PDF API
by igview-owner
Convert HTML content and webpage URLs to high-quality PDF documents instantly. HTML to PDF converter with customizable page formats (A4, Letter), scal...
Opens on Apify.com
About 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.
What does this actor do?
HTML To PDF API is a web scraping and automation tool available on the Apify platform. It's designed to help you extract data and automate tasks efficiently in the cloud.
Key Features
- Cloud-based execution - no local setup required
- Scalable infrastructure for large-scale operations
- API access for integration with your applications
- Built-in proxy rotation and anti-blocking measures
- Scheduled runs and webhooks for automation
How to Use
- Click "Try This Actor" to open it on Apify
- Create a free Apify account if you don't have one
- Configure the input parameters as needed
- Run the actor and download your results
Documentation
📄 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 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: json { "conversionType": "url", "url": "https://www.example.com" } Convert HTML to PDF: json { "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: json { "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: json { "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: json { "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: json { "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 json { "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 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 json { "waitForSelector": ".main-content", "waitTime": 5000 } 3. Use Descriptive File Names json { "outputFileName": "monthly-report-2024.pdf" } 4. Enable Background Graphics for Visual Content json { "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.
Categories
Common Use Cases
Market Research
Gather competitive intelligence and market data
Lead Generation
Extract contact information for sales outreach
Price Monitoring
Track competitor pricing and product changes
Content Aggregation
Collect and organize content from multiple sources
Ready to Get Started?
Try HTML To PDF API now on Apify. Free tier available with no credit card required.
Start Free TrialActor Information
- Developer
- igview-owner
- Pricing
- Paid
- Total Runs
- 65
- Active Users
- 10
Related Actors
Video Transcript Scraper: Youtube, X, Facebook, Tiktok, etc.
by invideoiq
Linkedin Profile Details Scraper + EMAIL (No Cookies Required)
by apimaestro
Twitter (X.com) Scraper Unlimited: No Limits
by apidojo
Content Checker
by jakubbalada
Apify provides a cloud platform for web scraping, data extraction, and automation. Build and run web scrapers in the cloud.
Learn more about ApifyNeed Professional Help?
Couldn't solve your problem? Hire a verified specialist on Fiverr to get it done quickly and professionally.
Trusted by millions | Money-back guarantee | 24/7 Support