Pagecraft

flatten

Flatten PDF

Bake form answers and annotations into the page so they cannot be changed.

Reads
a PDF — application/pdf
Writes
one file — PDFs
Tool page
/flatten-pdf

Example

Bake the answers in, so what the next reader opens cannot be edited.

Given

  • answered.pdf — a PDF carrying form fields

From code

            import { loadDocument, runOperation } from '@pagecraft/core';

const answered = await loadDocument({ bytes, name: 'answered.pdf' });

const [output] = await runOperation('flatten', [answered], {
  fields: true,
  annotations: true,
});
          

From a shell

            pagecraft flatten answered.pdf
          

What comes back

One PDF of 1 page.

This example is run by the test suite. If it stopped being true, the build would fail.

Options

fields--fields

boolean

Form fields

Bake the answers into the page, so the recipient cannot alter them.

Default: true

annotations--annotations

boolean

Annotations

Bake stamps, notes and drawings into the page as well.

Default: true

fontFile--font-file

Uint8Array

Font file

A TrueType or OpenType font, for text in a script the built-in fonts cannot draw.

What it cannot do

  • Flattening cannot be undone. The answers become part of the page, and nothing can read them back out as a form — which is the point of it.
  • A box the document never drew is drawn first, so that a form filled in by another tool is baked with its answers rather than blank. A box whose current state the document deliberately left blank — an unticked box — stays blank.
  • An annotation carrying no appearance has nothing to bake, so it is left as it is and reported.
  • Links are left working. Baking one would delete the jump and draw nothing in its place.
  • A hidden annotation is taken away rather than drawn, because a reader does not draw it either and a page that gained it would not be the same page.
  • A signature is not re-drawn. Its appearance is the signer’s, and flattening a signed document breaks the signature that covered it.