Introducing Templates

We're thrilled to introduce our new Templates feature! This latest addition empowers developers to create, manage, and reuse templates effortlessly from our dashboard or via API. Let's explore how templates can revolutionize your workflow for rendering PDFs, reducing repetitive setup tasks, and making your overall experience more efficient and seamless.

What are Templates?

Templates streamline your workflows by predefining all rendering options—such as Page, PDF, and Screenshot options. With a reusable setup, you can quickly launch new iterations of your documents in seconds!

Think of templates as a blueprint for your documents. Instead of redefining rendering settings for each API call, you can store them in editable templates and simply adjust variables (like templateData) as needed, without modifying the original template.

How it works

Dashboard:

  • Manage your templates effortlessly with our easy-to-use Templates section.
  • Create, edit, and delete templates directly from the dashboard.

API Integration:

Our API allows programmatic control over templates. Here’s how you can interact with the templates API:

MethodEndpointDescription
GET/v1/templatesFetch all templates
POST/v1/templatesCreate a new template
GET/v1/templates/:idGet a specific template by ID
PUT/v1/templates/:idUpdate an existing template
DEL/v1/templates/:idDelete a template

Template Syntax

We support templating with Handlebars, making it easy to dynamically insert variables such as user data, totals, and conditional sections. See Templating with Handlebars for more information.

API Examples

Below are a few ways you can interact with the Templates API using curl.

1. Create a new Template

When creating a template, ensure the htmlTemplate field is Base64 encoded. This is required to properly handle and transmit the HTML content within the API payload.

HTML Template

<html>
	<body>
		<h1>Invoice #{{invoiceNumber}}</h1>
	</body>
</html>
curl --request POST 'https://api.doczilla.app/v1/templates' \
	--header 'Authorization: Bearer <your token>' \
	--header 'Content-Type: application/json' \
	--data '{
  "name": "Invoice template",
  "output": "PDF",
  "variables": {
    "page": {
      "htmlTemplate": "PGh0bWw+Cgk8Ym9keT4KCQk8aDE+SW52b2ljZSAje3tpbnZvaWNlTnVtYmVyfX08L2gxPgoJPC9ib2R5Pgo8L2h0bWw+"
    }
  }
}'

2. Render a PDF from the Template

Generate a PDF from the template and save the output as invoice.pdf.

curl --request POST 'https://api.doczilla.app/v1/template/{id}' \
	--header 'Authorization: Bearer <your token>' \
	--header 'Content-Type: application/json' \
	--output 'invoice.pdf' \
	--data '{
  "page": {
    "templateData": {
      "invoiceNumber": "INV-1001"
    }
  }
}'

Key Advantages

  • Efficiency: Eliminate repetitive API configuration with reusable templates.
  • Flexibility: Make updates instantly to templates through the dashboard or API without re-deploying.
  • Scalability: Dynamically adjust settings with templateData for each request.

Whether you’re building invoices, reports, or customized customer communications, templates make it easier to maintain consistency and reduce manual overhead.

Get started with templates today!