Documentation

Overview

html2pdf.app is an HTML to PDF conversion API for developers. Send a public web page URL or raw HTML markup, and receive a ready-to-use PDF document in response.

Conversions run in headless Chromium, providing support for modern HTML, CSS, and JavaScript. The selected CSS media mode, available fonts and resources, and JavaScript load timing can affect the result, so test representative documents before using them in production.

Quick start

A standard conversion is one authenticated POST request. Send a public web page URL or raw HTML in the required html field, and the API returns the generated PDF as binary data.

EndpointPOST https://api.html2pdf.app/v1/generate
Request headerContent-Type: application/json
AuthenticationX-API-Key: <your-api-key>
  1. Get an API keyCreate an account and use the API key sent after registration.
  2. Choose the inputSet html to a publicly reachable URL or a raw HTML string.
  3. Handle the resultCheck the HTTP status, then save or stream the successful response as a .pdf file.

Send your first request

Replace <your-api-key>, run the command, and cURL will write the generated PDF to document.pdf in the current directory.

curl --fail --show-error \
--request POST https://api.html2pdf.app/v1/generate \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <your-api-key>' \
--data '{
  "html": "https://www.example.com"
}' --output document.pdf

Handle the response

  • A successful synchronous request returns the PDF file as binary data. Do not parse it as JSON or text.
  • Check for a successful HTTP status before saving the body or sending it to a browser. The --fail option makes the cURL example fail on HTTP 4xx and 5xx responses.
  • To generate in the background, include callBackUrl and follow the callback workflow instead.

Continue with your language

Open a complete guide with production-oriented setup, PDF response handling, request options, and callback examples.

View all code examples

Authentication

Authenticate every request by passing the X-API-Key header with your API key. You will receive your API key by email after registration.

Your API key is private. Use it from your backend, server-side scripts, or trusted jobs. Do not expose it in browser JavaScript, public repositories, or client-side templates.

Required header:

X-API-Key: <your-api-key>

Parameters

POST is recommended. Send parameters as a JSON request body to avoid query-string length and escaping problems. GET requests are also supported, but every query parameter must be URL-encoded; avoid GET for raw HTML and long template values.
ParameterTypeDescriptionDefault
htmlstringRaw HTML markup or a publicly reachable URL to convert.required
callBackUrlstringGenerates the document asynchronously and sends the result to this URL. The callback payload contains the base64-encoded PDF as {"document": "..."}. See Asynchronous requests & callbacks.null
statestringOptional value returned unchanged in the callback payload. Use it to associate the result with the original request.null
landscapebooleanUses landscape instead of portrait page orientation.false
formatstringPage format. Supported values:
Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6
A4
widthintegerCustom page width in pixels. Use together with the height parameter.null
heightintegerCustom page height in pixels. Use together with the width parameter.null
marginTop
marginRight
marginBottom
marginLeft
integerWhitespace, in pixels, between the page edge and its content.0
filenamestringSets the filename returned with the generated PDF.null
waitForintegerNumber of seconds to wait before generating the PDF. Use this when the page needs time to finish JavaScript or load asynchronous resources. Supported range: 0 to 10.0
mediastringCSS media mode used while rendering. Supported values: print and screen.screen
scalenumberScale applied to the document content. Supported range: 0.1 to 2.1
headerTemplate
footerTemplate
stringHTML markup rendered in the page header or footer. Use sufficient marginTop or marginBottom to make the template visible.null
userPasswordstringPassword required to open the encrypted PDF. Setting this value enables encryption.null
ownerPasswordstringOwner password that grants full access to the encrypted PDF and its permissions.null
permissionsarrayActions available to a user who opens the encrypted PDF. See the Encryption section for supported values.["print"]

Asynchronous requests & callbacks

By default, the API keeps the request open while it generates the PDF and then returns the document as binary data. Provide a callBackUrl when the document should be generated in the background instead.

Submit an asynchronous job

Send the request to the normal generate endpoint and authenticate with the same X-API-Key header used for synchronous conversions. When authentication succeeds and the request is accepted for processing, the API responds with 202 Accepted. A 202 response is confirmation that the job was queued; its body is not the generated PDF.

curl --fail --show-error \
--request POST https://api.html2pdf.app/v1/generate \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <your-api-key>' \
--data '{
  "html": "https://www.example.com",
  "callBackUrl": "https://your-app.com/webhooks/pdf",
  "state": "order-123"
}'

Receive the generated PDF

When processing finishes, html2pdf.app sends a POST request to callBackUrl. The callback JSON contains the generated PDF as a base64-encoded document value. Decode that value before saving or serving the PDF.

{
  "document": "JVBERi0xLjQ...==",
  "state": "order-123"
}

The optional state value is returned unchanged, which lets you associate the callback with the original order, report, or job.

Callback delivery

  • Use a publicly reachable HTTPS endpoint that accepts POST requests.
  • Process callbacks idempotently because a failed delivery can be attempted more than once.
  • If callback delivery fails, html2pdf.app retries it up to three times. After the third retry fails, the delivery is marked as failed.

Errors and HTTP statuses

Check the HTTP status before treating a response as a PDF. A non-2xx response is an error and must not be saved or returned with an application/pdf content type.

StatusMeaningRecommended action
400The source URL is not accessible or a request parameter is invalid.Confirm that the URL is publicly reachable and validate the request values before trying again.
401The API key is missing or invalid.Check the X-API-Key header and replace an invalid key.
403The account has reached a limit included in its current plan.Review the plan limits and the notification email sent to the account before retrying.
500An unhandled server error occurred.Retry after a short delay. Use increasing delays between repeated attempts and contact support if the error persists.
Do not automatically retry 400, 401, or 403 responses without first correcting the request, credentials, or account limit.

Fonts

The fonts listed below are available in the rendering environment.

You can also load Google Fonts or self-hosted web fonts with @font-face. Font stylesheets and files must be publicly reachable without authentication. If they load asynchronously, use waitFor to give the page time to finish rendering.
Fonts available in the PDF rendering environment
Andale MonoComic Sans MSNotoSansVerdana
ArialCourier NewNotoSerifWebdings
Arial BlackGeorgiaTahoma 
Arial NarrowImpactTimes New Roman 
Arial UnicodeMicrosoft Sans SerifTrebuchet MS 

Page breaks

Use CSS break rules to start each selected element on a new PDF page. Include the legacy page-break-* properties as a fallback.

<!doctype html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Paginated HTML</title>
    <style>
      .page {
        break-after: page;
        break-inside: avoid;
        page-break-after: always;
        page-break-inside: avoid;
      }

      .page:last-child {
        break-after: auto;
        page-break-after: auto;
      }
    </style>
  </head>
  <body>
    <section class="page">
      <h1>This is page 1</h1>
    </section>
    <section class="page">
      <h1>This is page 2</h1>
    </section>
    <section class="page">
      <h1>This is page 3</h1>
    </section>
  </body>
</html>

Encryption

Set userPassword to encrypt the PDF and require a password when it is opened. Use permissions to control which actions are available after opening it. An optional ownerPassword grants full access to the document and its permission settings.

PDF encryption uses 128-bit AES.

Encryption is enabled when userPassword is set. By default, permissions is ["print"], allowing a user who opens the document to print it.

ParameterTypeDescriptionDefault
userPasswordstringThe password that you want users to use for opening the PDF.null
ownerPasswordstringGrants full access to the PDF, including actions restricted by permissions and the ability to modify those permissions.null
permissionsarray
Field controlling what actions a user entering userPassword can perform.
print - allow printing.
modify - allow document modification, signing, and form-field changes.
copy - allow content copying and copying for accessibility.
edit - allow commenting.
fillform - allow filling of form fields.
extract - allow content copying for accessibility.
assemble - allow document assembly operations such as rotating, inserting, or deleting pages and managing bookmarks and thumbnails.
printbest - allow high-resolution printing when print is also allowed.
["print"]

cURL request example

curl --fail --show-error --output example.pdf --request POST \
  --url https://api.html2pdf.app/v1/generate \
  --header 'Content-Type: application/json' \
  --header 'X-API-Key: <your-api-key>' \
  --data '{
    "html": "https://example.com",
    "userPassword": "user",
    "ownerPassword": "owner",
    "permissions": ["print", "modify", "copy"]
}'

Data handling

Generated PDFs are processed only temporarily and are not permanently stored on our servers. Raw HTML or text submitted in the html parameter is not stored in conversion logs. Selected request metadata and a source URL supplied in html may be retained in those logs.

See the Privacy Policy and Data Processing Agreement for processing, retention, and security details.