v0.2.0 / MIT / TypeScript

Professional documents. Built dynamically.

Design document templates visually, bind JSON data, and generate consistent documents from your application.

npm install docstudio
Quick startSee examples
The DocStudio visual designer with a laboratory report open: toolbox on the left, the paper canvas in the middle, and the inspector for the selected table on the right
The DocStudio 0.2.0 designer with a laboratory report and its sample JSON loaded.

Documents are usually code

Invoices, reports and certificates tend to start as layout code: coordinates, string templates and one-off styling. Every change needs a developer, and the preview rarely matches the output.

DocStudio keeps them data

A template is JSON. A designer edits it visually, your data is merged into it, and one renderer produces the preview and the output. Designers change the layout, developers supply the data, and nobody edits the other's code.

How it works

Three steps, each usable on its own.

  1. 01

    Design

    Build the template in the visual designer, or write the JSON by hand. Templates are versioned data you can store anywhere.

  2. 02

    Bind

    Point text, tables and repeaters at paths in your JSON. Add expressions for totals, flags and formats.

  3. 03

    Render

    Compile to a resolved tree and render HTML. Print from the browser, or produce a PDF on a server.

What you get

Every item here exists in version 0.2.0. Limits are listed in the documentation.

Visual designer

A React editor with a paper-sized canvas, a toolbox of 14 components, an inspector, layers and undo.

Learn more about visual designer

Data binding

Bind any JSON to text, tables and repeaters. Expressions are a declarative AST with 35 built-in functions. Nothing is evaluated as JavaScript.

Learn more about data binding

Print and PDF

Print in the browser with printHtml, or render PDF on a server with Chromium through Playwright.

Learn more about print and pdf

Tables

Data tables with repeating headers, zebra rows, footers with totals and fixed rows, split across pages.

Learn more about tables

Right to left

English, Arabic and Urdu, with direction, alignment and table order mirrored.

Learn more about right to left

Reusable components

Publish a component once and pin it by version in the templates that use it.

Learn more about reusable components

A template and one call

The template is plain JSON. renderDocument compiles it with your data and returns HTML, or diagnostics when something is wrong. It never throws for template or data problems.

template.json
{
  "schemaVersion": "1.0.0",
  "body": [
    { "id": "title", "type": "text", "content": ["Invoice ", { "path": "number" }] },
    {
      "id": "lines",
      "type": "table",
      "source": { "path": "items" },
      "columns": [
        { "id": "name", "header": "Item", "cell": { "path": "name" } },
        {
          "id": "total",
          "header": "Total",
          "align": "end",
          "cell": { "fn": "mul", "args": [{ "path": "qty" }, { "path": "price" }] }
        }
      ]
    }
  ]
}
render.ts
import { renderDocument } from 'docstudio';

const data = {
  number: 'INV-1042',
  items: [
    { name: 'Design review', qty: 2, price: 120 },
    { name: 'Template setup', qty: 1, price: 480 },
  ],
};

const result = renderDocument(template, data, { target: 'print' });
if (!result.ok) {
  throw new Error(result.diagnostics.map((item) => item.message).join('; '));
}
const html = result.html;

Real output from real templates

These images are rendered by the published package from the templates and data on each example page.

All six examples with source

Architecture

Templates are migrated, validated, bound and compiled into a resolved document tree. The renderer turns that tree into HTML and CSS, and an output adapter prints it or produces a PDF. The designer preview and the output share the renderer.

ImportResponsibility
docstudioCore, render and renderDocument in one lightweight entry
docstudio/coreTemplate schema, validation, migration, binding, expressions, compilation
docstudio/renderResolved document tree to HTML and CSS
docstudio/designerThe React visual editor
docstudio/pdfBrowser-safe PDF client and printHtml
docstudio/serverNode PDF service on Playwright and Chromium

One npm package with one runtime dependency. See requirements.

Start in a few minutes

Install the package, render your first template, then add the designer when you need it.

npm install docstudio