Convert HTML to PDF - Web Page Converter API
PDF4me Convert HTML to PDF transforms HTML files and web content into professional PDF documents through advanced API integration. This powerful solution processes HTML content, including single HTML files or multiple HTML files within ZIP archives, converting them into high-quality PDF documents with customizable layout, formatting, and styling options. The API supports comprehensive HTML rendering with precise control over page dimensions, margins, scaling, and visual elements, making it ideal for web content archival, document generation, and automated PDF creation workflows.
Authenticating Your API Request
To access the PDF4me REST API, every request must include proper authentication credentials. Authentication ensures secure communication and validates your identity as an authorized user of the REST API.
Key Features
- HTML File Processing: Convert single HTML files or multiple HTML files within ZIP archives
- Web Content Rendering: Transform web pages and HTML content into professional PDF documents
- Customizable Layout: Support for Portrait and Landscape orientations with various page formats
- Precise Formatting: Multiple page sizes including A0-A8, Tabloid, Legal, Statement, and Executive
- Advanced Styling: Control over margins, scaling, background printing, and header/footer display
- ZIP Archive Support: Process multiple HTML files from compressed archives with index file specification
REST API Endpoint
The PDF4me REST API uses standard HTTP methods to interact with resources. All HTML to PDF conversion operations are performed through a single endpoint:
- Method: POST
- Endpoint:
/api/v2/ConvertHtmlToPdf
Supported Formats
The API provides comprehensive support for various HTML content types and page formats:
HTML Content Types
- Single HTML Files: Process individual .html files with complete content
- ZIP Archives: Handle multiple HTML files within compressed ZIP archives
- Web Pages: Convert live web content and HTML-based documents
- HTML with Assets: Support for HTML files with embedded CSS, JavaScript, and images
Page Formats
- Standard Sizes: A0, A1, A2, A3, A4, A5, A6, A7, A8
- Business Formats: Tabloid, Legal, Statement, Executive
- Custom Dimensions: Flexible page sizing for specific requirements
- Orientation Control: Portrait and Landscape layout options
Layout Options
- Portrait Mode: Vertical page orientation for standard documents
- Landscape Mode: Horizontal page orientation for wide content
- Margin Control: Precise top, bottom, left, and right margin settings
- Scaling Options: Content scaling from 0 to 0.8 for optimal fit
REST API Parameters
Complete list of parameters for the Convert HTML to PDF REST API. Parameters are organized by category for better understanding and implementation.
Important: Parameters marked with an asterisk (*) are required and must be provided for the API to function correctly.
Required Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| File Content* | Base64 | Map the file content from the previous action. Supports single HTML or HTML files in ZIP | JVBERi... |
| HTML File Name* | String | The source HTML file name with .html extension | document.html |
| index File Path* | String | Index file path required when the input file is ZIP | index.html |
| Layout* | String | The layout of the output PDF file. The options are Portrait or Landscape | Portrait |
| Format* | String | You can select any format - A0, A1, A2, A3, A4, A5, A6, A7, A8, Tabloid, Legal, Statement, Executive | A4 |
| Scale* | Decimal | Specify the scale as a decimal value between 0 and 0.8. The scale determines how much the content is resized. A smaller value reduces the size, while a larger value increases it within the allowed range. For example, entering 0.8 will scale the content to 80% of its original size. | 0.8 |
| TopMargin* | String | Specify the value for TopMargin based on your requirement. This defines the space between the top edge of the page (or container) and the content. The value must be provided with a valid unit (e.g., pixels). For example, entering 40px will set a top margin of 40 pixels. | 40px |
| BottomMargin* | String | Specify the value for BottomMargin according to your requirement. This setting controls the space between the bottom edge of the page (or container) and the content. The value must be entered with a valid unit (e.g., pixels). For example, entering 40px will create a bottom margin of 40 pixels, ensuring that the content is shifted upward from the bottom edge. | 40px |
| LeftMargin* | String | Specify the value for LeftMargin according to your requirement. This defines the space between the left edge of the page (or container) and the content. The value must include a valid unit (e.g., pixels). For example, entering 40px will create a left margin of 40 pixels, shifting the content inward from the left edge. | 40px |
| RightMargin* | String | Specify the value for RightMargin according to your requirement. This defines the space between the right edge of the page (or container) and the content. The value must be provided with a valid unit (e.g., pixels). For example, entering 40px will create a right margin of 40 pixels, shifting the content inward from the right edge. | 40px |
| PrintBackground* | Boolean | Selecting true will print the background (such as colors, patterns, or images) along with the content in the PDF. Selecting false will exclude the background, and only the main content will be displayed in the PDF. | true |
| DisplayHeaderFooter* | Boolean | Selecting true will include the header and footer (such as page numbers, titles, or other set information) in the PDF. Selecting false will exclude the header and footer, so only the main content will be shown. | true |
Output
The PDF4me Convert HTML to PDF REST API returns a response that can be viewed in multiple formats. Choose the view that best fits your needs:
- JSON
- Table
- Schema
- Binary
JSON Response Format
The raw JSON response from the API:
{
"File Content": "Output file content from PDF4me action",
"File Name": "Output file name from PDF4me action"
}
Table View
Response data in a structured table format:
| Parameter | Value |
|---|---|
| File Content | Output file content from PDF4me action |
| File Name | Output file name from PDF4me action |
Schema View
The data structure and types of the response:
2 items
File Content: AB Output file content from PDF4me action
File Name: AB Output file name from PDF4me action
Type Indicators:
AB= String
Binary Data View
The actual converted PDF file data and metadata:
data
─────────────────────────────
File Content: Output file content from PDF4me action
File Name: Output file name from PDF4me action
Binary Data Access:
- PDF Content: Ready for download or further processing
- HTML Conversion: Complete web content to PDF transformation
Request Example
Header
Content-Type: application/json
Authorization: YOUR_API_KEY
Note: Get your API key from the PDF4me Dashboard
Payload
{
"docContent": "Please put HTML base64 content",
"docName": "output.pdf",
"indexFilePath": "please input file path",
"layout": "Portrait",
"format": "A4",
"scale": 0.8,
"topMargin": "40px",
"bottomMargin": "40px",
"leftMargin": "40px",
"rightMargin": "40px",
"printBackground": true,
"displayHeaderFooter": true
}
Code Samples
The PDF4me Convert HTML to PDF REST API provides code samples in multiple programming languages. Choose the language that best fits your development environment:
- C#
- Java
- JavaScript
- Python
- Salesforce
- n8n
- Google Script
- AWS Lambda
Google Script Sample
Google Apps Script implementation for Google Workspace integration:
HTML Conversion Features
Web Content Processing
- HTML Rendering: Advanced HTML parsing and rendering engine
- CSS Support: Complete CSS styling and layout preservation
- JavaScript Handling: Support for dynamic content and interactive elements
- Asset Integration: Images, fonts, and external resources processing
Document Customization
- Page Layout: Portrait and Landscape orientation control
- Format Selection: Multiple page sizes from A0 to A8 and business formats
- Margin Control: Precise top, bottom, left, and right margin settings
- Scaling Options: Content scaling for optimal page fit and readability
Advanced Styling
- Background Printing: Control over background colors, patterns, and images
- Header/Footer: Page numbering, titles, and document information
- Content Preservation: Maintains original HTML structure and formatting
- Quality Output: High-resolution PDF generation with professional appearance
Industry Use Cases & Applications
- Business & Enterprise
- E-commerce & Retail
- Legal & Professional Services
- Education & Training
- Government & Compliance
Business & Enterprise Use Cases
- Document Generation: Create PDF reports and documents from HTML templates
- Business Reports: Convert HTML business reports to PDF
- Corporate Documentation: Transform HTML corporate documents to PDF
- Business Dashboards: Convert HTML dashboards to PDF for reporting
E-commerce & Retail Use Cases
- E-commerce: Generate product catalogs and invoices from HTML content
- Product Catalogs: Convert HTML product catalogs to PDF
- Invoices: Transform HTML invoices to PDF
- E-commerce Reports: Convert HTML e-commerce reports to PDF
Legal & Professional Services Use Cases
- Legal & Compliance: Convert web-based legal documents and contracts to PDF
- Legal Documents: Transform HTML legal documents to PDF
- Contracts: Convert HTML contracts to PDF
- Compliance Documentation: Transform HTML compliance documents to PDF
Education & Training Use Cases
- Education & Training: Transform online courses and educational content to PDF format
- Online Courses: Convert HTML online courses to PDF
- Educational Content: Transform HTML educational content to PDF
- Training Materials: Convert HTML training materials to PDF
Government & Compliance Use Cases
- Web Content Archival: Convert web pages and HTML content to PDF for long-term preservation
- Public Records: Transform HTML public records to PDF for archival
- Government Documentation: Convert HTML government documents to PDF
- Regulatory Documentation: Transform HTML regulatory documents to PDF