Skip to main content

Convert HTML to PDF

ConvertConvert 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

Quick reference

Endpoint: POST /api/v2/ConvertHtmlToPdf · Required: api-key, docContent, docName, indexFilePath, layout, format, scale, margins, printBackground, displayHeaderFooter, IsAsync

Try it live

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.

Loading API Tester...

Overview, parameters, and 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).
  • AsyncIsAsync returns 202 with Location URL for polling.
Best for

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.

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.

Get Help