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 create and re-use templates text objects, images, CSS and HTML5 styles, Javascript, and built-in barcodes (QR Code, Datamatrix, Code 128, Code 39, and many others), conditional logic, reusable content blocks (headers and footers), custom fonts.

SIGN UP FOR FREE

advanced html template with demo added


Sample PDF output from advanced HTML template with barcodes:
pdfco-advanced-html-to-pdf-template-output.pdf

Handlebars & Mustache Template Support

PDF.co supports Handlebars and Mustache HTML templates. The Handlebars and Mustache’s HTML code contains special macros like {{Macro}}. These macros work as placeholders for data that you want to put in its place. You can also add barcodes using a macro: [[barcode:QR Code 12345]] or [[barcode:QR Code {{variable1}}]]

Custom Script Support

You can use the Custom Script to disable clickable links in your PDF output. You can also use it to hide elements by class name or id.

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 reports from a clean slate using JSON data or CSV data.

Web API Supports Multiple Languages

PDF.co platform can be used by software developers from programming languages such as PHP, Javascript, .NET and ASP.NET, C#, Java, Visual Basic, and many others. Find source code samples in our API documentation.

Business Automation Platforms Integrations

If you are not a developer, you can also easily automate your PDF operations via popular business automation platforms: ZapierMakeAirtableSalesforceGoogle Apps Script, and 300+ more.

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

Generate PDF from HTML Template using C# code here.

Generate PDF from HTML Template using Java code here.

Generate PDF from HTML Template using JavaScript code here.

Generate PDF from HTML Template using Python code here.

Generate PDF from HTML Template using PHP code here.

Sign Up