Convert HTML to PDF
Convert → Convert HTML to PDF
The Convert HTML to PDF API turns HTML (or ZIP of HTML files) into a PDF. You send docContent (Base64), docName, indexFilePath (e.g. sample.html), layout (Portrait/Landscape), format (A4, etc.), scale, margins, printBackground, displayHeaderFooter, and IsAsync. The API returns the PDF (or 202 + Location for async). Use the tester below to try it; more details are in the sections that follow.
Try the Convert HTML to PDF API
Endpoint: POST /api/v2/ConvertHtmlToPdf · Required: api-key, docContent, docName, indexFilePath, layout, format, scale, margins, printBackground, displayHeaderFooter, IsAsync
Use the form below to send your API key, HTML (Base64), index file path, layout, format, scale, margins, and options. The response is the PDF (or polling URL when async). No code required—fill the fields and click Send request.
Overview, parameters, and use cases
- Overview
- Parameters
- Use cases
What is Convert HTML to PDF?
This endpoint converts HTML content into a PDF. You provide the HTML (Base64; single file or ZIP with multiple HTML files), docName, indexFilePath (path to the main HTML file), layout (Portrait/Landscape), format (A0–A8, Tabloid, Legal, etc.), scale (0.1–2.0), margins (top, bottom, left, right), printBackground, displayHeaderFooter, and IsAsync. The API returns the PDF or a Location URL to poll when async.
Key features
- Single or ZIP – One HTML file or a ZIP containing multiple HTML files.
- Layout and format – Portrait/Landscape; page sizes A0–A8, Tabloid, Legal, etc.
- Scale and margins – Control scaling and margin spacing (e.g. 40px).
- Async – IsAsync returns 202 with Location URL for polling.
Use when you need PDFs from HTML or web-style content. For live URLs use Convert URL to PDF; for Markdown use Convert Markdown to PDF.
API parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| api-key | string | Yes | Your PDF4me API key, Base64 encoded. Get it from the dashboard. |
| docContent | base64 | Yes | HTML file content (Base64) or ZIP of HTML files. |
| docName | string | Yes | Output file name (e.g. output.pdf). |
| indexFilePath | string | Yes | Path to the source HTML file (e.g. sample.html). |
| layout | string | Yes | Portrait or Landscape. |
| format | string | Yes | Page size: A0–A8, Tabloid, Legal, Statement, Executive. |
| scale | number | Yes | Scaling factor (0.1–2.0). |
| topMargin, bottomMargin, leftMargin, rightMargin | string | Yes | Margin spacing (e.g. 40px). |
| printBackground | boolean | Yes | Include background colors and images. |
| displayHeaderFooter | boolean | Yes | Show header and footer in PDF. |
| IsAsync | boolean | Yes | Enable asynchronous processing. |
When to use Convert HTML to PDF
- Reports – Convert HTML reports or dashboards to PDF.
- Documentation – Turn HTML docs or README-style content into PDF.
- Pipelines – Generate HTML from templates then convert to PDF for distribution.
For request/response schemas and code samples, see Convert HTML to PDF in the PDF4me API docs.
Prerequisites
Before using this endpoint, make sure you have:
- A valid PDF4me API key (Get your API Key)
- An HTML file in Base64 format or a public URL to an HTML file
Response Format
The API returns a PDF document:
- Status 200: HTML to PDF conversion completed immediately - binary PDF content in response body
- Status 202: Request accepted and processing asynchronously - use the Location header URL to poll for results
For asynchronous requests, poll the Location URL until status 200 is returned with the PDF document.