Skip to main content
Forme can embed structured JSON data inside a PDF as a hidden file attachment. The PDF looks and prints identically — the data is invisible to viewers but can be extracted programmatically. This makes PDFs self-describing: an invoice carries its line items, a report carries its dataset.

Embedding data

Pass embedData when rendering:
The embedData value can be any JSON-serializable object. It’s compressed and stored as a forme-data.json file attachment inside the PDF.

Extracting data

Use extractData to read the embedded JSON back out:
extractData returns null for PDFs that don’t contain embedded data (including non-Forme PDFs).

Three patterns

1. Programmatic (opt-in)

When using @formepdf/core directly, pass embedData in the options. You choose what to embed — it doesn’t have to match the template data.

2. Hosted API (automatic)

The Forme hosted API automatically embeds the request body into every rendered PDF. No opt-in needed.

3. Templates (automatic)

When using renderTemplate(), the data JSON you pass is automatically embedded.

Use cases

  • Invoice processing: Accounting systems extract line items from PDFs without OCR.
  • Form submissions: PDF forms carry the structured form data for downstream systems.
  • Archival: Store the source data alongside its visual representation. Regenerate or audit later.
  • Data exchange: Send a PDF that’s both human-readable and machine-readable. The recipient can parse the data or just read the document.
  • Round-tripping: Extract data from a PDF, modify it, re-render a new PDF.

How it works

The data is stored as a FlateDecode-compressed EmbeddedFile stream in the PDF, referenced via a /Names tree with a /FileSpec entry pointing to forme-data.json. This follows the PDF 1.7 specification for file attachments. The attachment is invisible in PDF viewers but can be listed in some readers’ attachment panels.