# HTML to PDF API

> This HTML to PDF API renders raw HTML markup into downloadable PDF files. Send your escaped HTML string to receive a signed download link, an expiration timestamp, and the generated document filename.

**Endpoint:** `POST https://api.apiverve.com/v1/htmltopdf`  
**Category:** Documents  
**Cost:** 20 credits per call  
**Canonical page:** https://apiverve.com/marketplace/htmltopdf

## Overview

Use it as a PDF generator API for invoices, reports and receipts: post your HTML and get back a link to the finished file. The HTML is rendered in a headless browser, so your CSS layout carries over, and the response holds a download URL with its expiry time. Page margins and landscape orientation are available on paid plans. Official SDKs wrap the call, so HTML to PDF conversion is one function call from Node.js, Python, C#, Go and other languages.

## Authentication

Every call carries your key in an `x-api-key` header. The same key works across the whole
APIVerve catalog — there are no per-API subscriptions. Responses always use the same three
top-level keys: `status`, `error`, and `data`.

## Example request

```bash
curl -X POST "https://api.apiverve.com/v1/htmltopdf" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html":"<!doctype html> <html>  <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>","marginTop":0.4,"marginRight":0.4,"marginBottom":0.4,"marginLeft":0.4,"landscape":false,"format":"value","scale":1,"printBackground":true,"pageRanges":"value","headerTemplate":"value","footerTemplate":"value"}'
```

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `html` | string | Yes | The HTML content to convert to PDF. Ensure that the HTML is escaped properly. length 0-500000 |
| `marginTop` | number | No | The top margin of the PDF in inches from 0 to 4 (e.g., 0.5). default 0.4. range 0-4. Premium field |
| `marginRight` | number | No | The right margin of the PDF in inches from 0 to 4 (e.g., 0.5). default 0.4. range 0-4. Premium field |
| `marginBottom` | number | No | The bottom margin of the PDF in inches from 0 to 4 (e.g., 0.5). default 0.4. range 0-4. Premium field |
| `marginLeft` | number | No | The left margin of the PDF in inches from 0 to 4 (e.g., 0.5). default 0.4. range 0-4. Premium field |
| `landscape` | boolean | No | Set to true for landscape orientation. default false. Premium field |
| `format` | string | No | Paper size. default A4. One of: A4, Letter, Legal, Tabloid, Ledger, A3, A5, A6. Premium field |
| `scale` | number | No | Zoom applied to the page content, 0.1 to 2. default 1. range 0.1-2. Premium field |
| `printBackground` | boolean | No | Print background colours and images; set false for an ink-saving document. default true. Premium field |
| `pageRanges` | string | No | Only these pages, e.g. 1-3, 5. Premium field |
| `headerTemplate` | string | No | HTML printed at the top of every page. Spans with class pageNumber, totalPages, date, title or url are filled in. Use inline styles with a font-size (Chromium defaults to a tiny font) and leave room with marginTop. Premium field |
| `footerTemplate` | string | No | HTML printed at the bottom of every page, with the same placeholders as headerTemplate, e.g. <span class="pageNumber"></span> of <span class="totalPages"></span>. Premium field |

## Response fields

- `marginLeft` — string · Left margin of the PDF in inches
- `marginRight` — string · Right margin of the PDF in inches
- `marginTop` — string · Top margin of the PDF in inches
- `marginBottom` — string · Bottom margin of the PDF in inches
- `landscape` — boolean · Whether the PDF is in landscape orientation
- `format` — string · Paper size used
- `scale` — number · Content zoom used
- `pageCount` — number · Number of pages in the generated PDF; null if it could not be read
- `pdfName` — string · Unique identifier filename for the generated PDF
- `expires` — number · Unix timestamp when the PDF download URL expires
- `downloadURL` — string · Signed URL to download the generated PDF file

## Sample response

```json
{
  "status": "ok",
  "error": null,
  "data": {
    "marginLeft": "0.4in",
    "marginRight": "0.4in",
    "marginTop": "0.4in",
    "marginBottom": "0.4in",
    "landscape": false,
    "format": "A4",
    "scale": 1,
    "pageCount": 1,
    "pdfName": "c064eacc-c29f-43a1-8375-a4b2562ea9d8.pdf",
    "expires": 1766096665366,
    "downloadURL": "https://storage.googleapis.com/apiverve-helpers.appspot.com/htmltopdf/c064eacc-c29f-43a1-8375-a4b2562ea9d8.pdf?GoogleAccessId=1089020767582-compute%40developer.gserviceaccount.com&Expires=1766096665&Signature=R%2Ft%2FXcR%2B8bXzCi5ztc01YeE%2Bbn1ZR%2BCyeoqgHpSB1z0LO3SetOSoWYVoon5IG4vUU9W30Rmw6owErorZal%2FHdgpmcPAYx3eTx5dPaD45tFSCgIfpRloi0DBLse%2Fzy4sb0k3XgweiHZUdZu3jKMi1HVDJa2j2ervAFfwDfxGHUDXH5wwFKqnv%2BIw%2Fu7MBsKMDCNMWYESE7Aicz6eL0Lxz8P6oazJX0akKlLDhkgKiIqF3VtjGIh36RzK4WGBpU36JFZ7SCZZGHNiHyt3%2FBdyjPRA8N1fky%2Bv%2BjR%2BTTlO9BpWcjImNJM6nvVfmICEfcbLqL2MvVldfPAFKyEv2zCrCLA%3D%3D"
  }
}
```

## Use cases

- **Billing Receipt Generation** — SaaS billing engines convert rendered invoice templates into downloadable PDF links to attach to customer payment receipts.
- **Exporting Analytics Dashboards** — When clients export quarterly business metrics, reporting portals turn dynamic table markup into formatted PDF documents for offline distribution.
- **Warehouse Packing Slips** — Feed order summaries directly into PDF documents so distribution centers can fetch printable package inserts via temporary download URLs.
- **Archiving Legal Agreements** — To store finalized contracts permanently, digital signature services convert signed HTML agreement summaries into dated PDF records.

## SDKs

- **npm** — `npm install @apiverve/htmltopdf` (https://www.npmjs.com/package/@apiverve/htmltopdf)
- **PyPI** — `pip install apiverve-htmltopdf` (https://pypi.org/project/apiverve-htmltopdf/)
- **NuGet** — `dotnet add package APIVerve.API.HTMLtoPDF` (https://www.nuget.org/packages/APIVerve.API.HTMLtoPDF)
- **Source** — https://github.com/apiverve/htmltopdf-api

## More

- Full reference: https://docs.apiverve.com/ref/htmltopdf
- Get an API key: https://dashboard.apiverve.com
- Full catalog: https://apiverve.com/marketplace
