HTML Template to PDF Benefits

Convert HTML to PDFYou can create PDF from scratch or PDF template using the HTML Template to PDF API. With this API, you can use text objects, images, text fields, checkboxes, and other fillable fields to generate new PDFs.

The API’s engine can also generate a PDF template using an HTML template created from Handlebars and Mustache.

Handlebars & Mustache Template Support

PDF.co supports Handlebars & Mustache HTML templates. The Handlebars & Mustache’s HTML code contains special macros. These special macros serve as placeholders for data that you want to put in its place.

SIGN UP FOR FREE

PDF Page Customization

The HTML Template to PDF API supports paper size, margin, and orientation customization. You can also add an optional header and footer information on every page.

Multiple Source Support

The API can generate PDF from a clean slate using different objects such as text, images, editable fields, etc. It can also generate PDFs from an HTML template or raw HTML code and URL.

On-Premise API Server

At PDF.co we offer on-demand and on-premise API Server to meet our customers’ needs. The on-premise API Server is capable of handling simultaneous jobs processing PDF files on AWS hosted server. To learn more, please contact our customer support team.

HTML Template to PDF Integrations

PDF.co has over 300+ app integration. Kindly explore our following plugins:

HTML Template to PDF Samples & Demo

In this demonstration, we will use a simple inline HTML template to generate a PDF. This HTML template has two macros {{variable1}} and {{variable2}} that we will fill with data from a JSON template. Below are the images of the source and output files.

PDF.co PDF Generator API Source File
Images of Source HTML template and Output PDF

Let’s go over the HTML Template to PDF parameters before we start coding.

Endpoint

URL: https://api.pdf.co/v1/pdf/convert/from/html
Method: POST

profilesoptional. Must be a String. Set custom configuration. See profiles examples here

Parameter Description
html required. HTML template with Mustache and Handlebars template.
margins optional. Set CSS style margins.
orientation optional. Set to Portrait or Landscape.
paperSize optional. The letter is set by default.
printBackground optional. Set to true by default
header optional. Set to HTML for the header to be applied on every page at the header.
footer optional. Set to HTML for the header to be applied on every page at the header.
templateData optional. Set to string with JSON data for a template if your HTML is a template (Handlebars & Mustache style)
async optional. Runs processing asynchronously. Returns jobId to use with job/check: true or false

cURL Code Snippet

curl --location --request POST 'https://api.pdf.co/v1/pdf/convert/from/html' \
--header 'x-api-key: {{x-api-key}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "html": "Sample template: {{variable1}} and {{variable2}}",
    "name": "result.pdf",
    "margins": "5px 5px 5px 5px",
    "paperSize": "Letter",
    "orientation": "Portrait",
    "printBackground": true,
    "header": "",
    "footer": "",
    "async": false,
    "encrypt": false,
    "templateData": "{\"variable1\": \"Hello from variable1\", \"variable2\": \"Hello from variable 2\"}"
}'

Now it’s time to see the cURL code above in action.

PDF.co PDF Generator API Output PDF
HTML Template to PDF Output

Sign Up