Polotno

PDF GENERATION

PDF generator API – create PDFs from JSON at scale

Generate PDFs programmatically from a Polotno design schema. Use the Cloud Render API or run the renderer yourself, and produce thousands of personalized documents from one template.

Polotno generates PDFs from structured JSON. A design describes pages, text, images, and vector paths with explicit positions, fonts, and colours. Fill a template with different data and control how text fits its boxes. Generation runs through the Cloud Render API or on your own infrastructure. Choose vector PDF export for selectable text.

How the PDF creation API works

Every Polotno design is a JSON document. Generating a PDF is a matter of producing that JSON (by hand, from a template, or from a database row) and passing it to a renderer.

From the editor

js
import { createStore } from 'polotno/model/store';
import { jsonToPDFBlob } from '@polotno/pdf-export/browser';

const store = createStore({ key: 'YOUR_KEY' });
store.loadJSON(design);
await store.waitLoading();

const blob = await jsonToPDFBlob(store.toJSON()); // vector, selectable text

From a server

The same schema renders without a browser session. Post the design JSON to the Cloud Render API or run the renderer inside your own infrastructure. Both paths accept the same design JSON; match fonts, assets, and export settings when comparing output. See rendering modes for the trade-offs.

Template plus data

The pattern that makes PDF generation useful at volume is one template and many records. Mark the values that change as template variables, such as {{customer}} in a text, then fill a copy for each record and render it.

js
import { jsonToPDF } from '@polotno/pdf-export';
import { resolveVariables } from '@polotno/schema/variables';

for (const { id, ...record } of rows) {
  const { design, issues } = resolveVariables(template, record);
  if (issues.length) console.warn(id, issues);
  await jsonToPDF(design, `./${id}.pdf`);
}

The fill needs no editor store, and it works the same in the browser. The Cloud Render API takes the template and one record per job and fills it the same way.

This pattern supports certificates, invoices, tickets, labels, personalized mailers, and statements. Set the template's text-fit behavior and test long values: changing content can resize a text box, shrink the font, or truncate text, depending on the configured overflow policy.

For programmatic template management, see create and manage templates via API.

Document generation from structured data

A document generation pipeline usually has three parts: a template, a data source, and a renderer. Polotno provides the first and third, and stays agnostic about the second. For the wider picture beyond PDF, see document generation.

  • Template: authored in the editor by a non-developer, stored as JSON in your database.
  • Data: whatever your application already holds: a row, an API response, an LLM output.
  • Render: Cloud Render API or self-hosted rendering for PDF, PNG, JPEG, SVG, HTML, and other supported formats, from the same schema.

Storing templates as JSON rather than as PDF blobs means they stay queryable and diffable, and a marketing user can edit one without a deploy.

Vector output, not a screenshot

Reach for @polotno/pdf-export (jsonToPDF in Node, jsonToPDFBlob in the browser) or the Cloud Render API with vector: true. The built-in store.saveAsPDF() is the raster path. It flattens each page to an image, which is not what you want for a generated document.

With the vector path, text is embedded as subsetted fonts and stays selectable and searchable; shapes stay paths. This matters for three reasons: file size stays small, the document remains accessible to text extraction, and print output scales without resampling.

Print-oriented generation supports CMYK, spot colours, bleed, and crop marks, and can target PDF/X-1a or PDF/X-4 for a commercial printer. Full detail in the PDF export docs. For what a printer checks in a PDF, and why, see how to generate a print-ready PDF in JavaScript.

What this does not cover

PDF generation here means producing a document from a design schema. It does not include filling AcroForm fields in an existing PDF, applying OCR to a scan, or compressing an existing file. If you need to open an existing PDF and change it, that is PDF editing; if you need to move a PDF into another format, that is PDF conversion.

Related reading

Embed creative infrastructure into your product

TRUSTED BY

100,000+

CREATORS

300+

BUSINESSES

ExpediaUnbounceLovePopPostGridPredis.ai