Skip to main content

POST /v1/pdf/convert/from/html

Converts a predefined HTML template into a PDF document using its Template ID. The template must be created and saved in the HTML to PDF Templates section of the dashboard.

Attributes

Attributes are case-sensitive and should be inside JSON for POST request. for example: { "url": "https://example.com/file1.pdf" }
Remember to ensure that request sizes are less than 4 mb in file size. For more information, see Request Size Limits.

HTML Templates

During conversion, the API performs variable substitution and built-in helper evaluation using your templateData, but does not execute any arbitrary JavaScript within the template itself. After the template is rendered into HTML, a headless browser processes the page and executes any in-page JavaScript triggered on load. External or dynamically loaded JavaScript libraries may run if accessible, but execution is not guaranteed in all environments. This separation ensures secure, predictable template handling and accurate rendering of interactive web content.
Use the dashboard to manage your HTML to PDF Templates. Templates use {{Mustache}} and Handlebars templating syntax. You just need to insert macros surrounded by double brackets like {{ and }}. Some Examples of macro inside html template:
  • {{variable1}} will be replaced with test if you set templateData to { "variable1": "test" }
  • {{object1.variable1}} will be replaced with test if you set templateData to { "object1": { "variable1": "test" } }
  • Simple conditions are also supported. For example: {{#if paid}} invoice was paid {{/if}} will show invoice was paid when templateData is set to { "paid": true }.

Handlebars

Handlebars extends Mustache with powerful features like conditional logic, loops, and custom helper functions. You can use Handlebars helpers like #if, #unless, #each (see https://handlebarsjs.com/guide/builtin-helpers.html) but you can also define your own helper functions for complex calculations and data manipulation.

Key Handlebars Features:

  • Variable substitution: {{variable}} syntax for inserting data
  • Conditional logic: {{#if}} and {{#unless}} blocks for conditional rendering
  • Loops: {{#each}} for iterating over arrays and objects
  • Nested objects: Accessing properties with dot notation like {{company.name}}
  • Built-in helpers: Using Handlebars’ built-in functionality for common operations

Sample JSON input

If you use JSON as input then make sure to escape it first (with JSON.stringify(dataObject) in JS). Escaping is when every " is replaced with \". Example with " be escaped as \" then: "templateData": "{ \"paid\": true, \"invoice_id\": \"0002\", \"total\": \"$999.99\" }".

Sample CSV input

The header and footer parameters can contain valid HTML markup with the following classes used to inject printing values into them:
  • date: formatted print date
  • title: document title
  • url: document location
  • pageNumber: current page number
  • totalPages: total pages in the document
img: tag is supported in both the header and footer parameter, provided that the src attribute is specified as a base64-encoded string. For example, the following markup will generate Page N of NN page numbering:
An example with an advanced header and footer. Note that the top and bottom page margins are important because page content may overlap the footer or header.

Query parameters

No query parameters accepted.

Responses

Example Payload

To see the request size limits, please refer to the Request Size Limits.

Example Response

To see the main response codes, please refer to the Response Codes page.
Inconsistent URL Encoding in cURL Output: When using cURL to make API requests, the output JSON may show URL characters encoded as Unicode escape sequences. For example, the ampersand character (&) may appear as \u0026 in the cURL output. This is normal JSON encoding behavior and does not affect the validity of the URL. The URL will function correctly when used, as JSON parsers automatically decode these escape sequences. If you’re parsing the response programmatically, your JSON parser will handle this conversion automatically.

Code Samples