Skip to main content

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

ParameterTypeDescriptionExample
File Content*Base64Map the file content from the previous action. Supports single HTML or HTML files in ZIPJVBERi...
HTML File Name*StringThe source HTML file name with .html extensiondocument.html
index File Path*StringIndex file path required when the input file is ZIPindex.html
Layout*StringThe layout of the output PDF file. The options are Portrait or LandscapePortrait
Format*StringYou can select any format - A0, A1, A2, A3, A4, A5, A6, A7, A8, Tabloid, Legal, Statement, ExecutiveA4
Scale*DecimalSpecify 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*StringSpecify 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*StringSpecify 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*StringSpecify 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*StringSpecify 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*BooleanSelecting 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*BooleanSelecting 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 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"
}

Request Example

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# (CSharp) Sample

Complete C# implementation for HTML to PDF conversion:

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 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

Get Help