logoKeepMot API
DocsAPI ReferenceHTML to PDF API

PDF · HTML Render

HTML to PDF API

Convert an HTML fragment into a PDF while preserving browser layout, CSS styling, fonts, and page breaks.

Use this endpoint when your source document is HTML. Supply a complete HTML document or a fragment; fragments are wrapped in a standard HTML document before rendering.

The generated PDF is charged one Token per page. Authenticate every request with an active API Key from the API Keys page.

Endpoint

POST/html-to-pdf

Content-Type

application/json

Success

200 · application/pdf

Cache

no-store

Request body

JSON
data
stringrequired

A non-empty HTML document or HTML fragment. The maximum processed HTML size is 5 MB.

output
object

Optional output controls.

output.mode
"binary"

Optional. Only binary is supported and returns PDF bytes in the response body.

output.file_name
string

Optional PDF download name. A safe .pdf name is generated when omitted.

Request example

Send the JSON body below with a POST request. A successful response contains the generated PDF bytes.

JSON example
{
  "data": "<main style=\"font-family: Arial; padding: 40px\"><h1>Invoice #1048</h1><p>Total: $145.00</p></main>",
  "output": {
    "mode": "binary",
    "file_name": "invoice.pdf"
  }
}

Authentication

Set Authorization: Bearer YOUR_API_KEY. The key must be active, unexpired, and have enough Token balance for every generated page.

HTML rendering

Use inline styles or externally reachable assets. Page size, print CSS, and page breaks can be controlled with standard HTML and CSS.

Responses

StatusMessageDescription
200PDF generatedThe response body contains application/pdf bytes.
400Invalid HTML requestThe JSON body is invalid, data is empty, or output.mode is not binary.
401Authorization requiredThe Bearer API key is missing, invalid, expired, disabled, or its user is inactive.
402Insufficient Token balanceThe authenticated account does not have enough Tokens for the generated PDF pages.
413HTML too largeThe processed HTML document exceeds the 5 MB limit.
415Unsupported mediaThe request Content-Type is not application/json.
422HTML to PDF failedThe HTML renderer could not produce a valid PDF.
502HTML renderer unavailableThe upstream HTML rendering service failed or returned an empty PDF.