docs

Form fields, digital signatures and encryption

Templates can contain interactive form fields ("type": "field"). The signing key and passwords are never part of a template. They come from CLI flags, the server's flags or the library Options, so one template can be rendered unsigned, signed or encrypted.

Form fields

{ "type": "field", "id": "name", "x": 40, "y": 96, "width": 250, "height": 20,
  "fontSize": 10, "stroke": "#9ca3af", "fill": "#f9fafb",
  "field": { "kind": "text", "name": "customerName", "value": "{{customer.name}}", "required": true } }
field property Applies to Meaning
kind all text, checkbox, radio, dropdown or signature (required)
name all Field name (PDF /T), required, no .. Form data is exported under this name.
value text, checkbox, radio, dropdown Default value; {{bindings}} allowed. Checkbox: a truthy value (not "", false, 0, no, off) checks it. Radio: the button whose option equals the value is selected. Dropdown: the selected choice.
option radio (required), checkbox Value this radio button stands for; checkbox export value (default Yes).
options / optionsFrom dropdown Fixed choices, and/or a data path to an array (strings, or objects with label/value/name).
required, readOnly all PDF field flags.
multiline, password, maxLength text Multi-line input (default value wraps); masked input (default value not stored); character limit.
editable dropdown Allow typed values that are not in the list.
tooltip all Tooltip and accessible name (/TU).
label signature Placeholder text while unsigned (default Signature).

Look. The engine draws each field's appearance: stroke is the border (default grey, "none" for none), fill the background, and font, size, colour and align style the value. The same appearance appears in the PNG preview and in every PDF viewer (the PDF carries appearance streams, NeedAppearances is not used). When a user edits a text field, the viewer redraws it with Helvetica at the template's font size. Unicode default values still display correctly, because the initial appearance uses the embedded template font.

Default sizes (when width/height are omitted): text and dropdown 150×20, checkbox and radio 12×12, signature 180×50.

Same name = same field. Elements that share a name are widgets of one field. A field in the header or footer (or a repeated element) is one field with a widget on every page, so typing initials on page 1 fills them in on every page. Radio buttons with the same name form one group. Using a name for two different kinds is an error.

Fields may be rotated (any angle; the widget rectangle is the rotated box's bounding box). However, viewers redraw an edited value unrotated unless the angle is a multiple of 90°.

Signing (PAdES)

liuska render -t form.json -d data.json -o signed.pdf \
  --sign-p12 signer.p12 --sign-password env:P12_PASSWORD \
  --sign-reason "Approved" --sign-location "Helsinki" [--sign-field approver] [--tsa-url https://tsa.example/]
# or a PEM key + certificate chain:
liuska render ... --sign-key signer.key --sign-cert chain.pem

Encryption

liuska render ... --user-password env:PDF_PASSWORD --owner-password file:/run/secrets/owner --permissions print,fill-forms
liuska render ... --encrypt --permissions none      # opens without a password, but restricted

AES-256 (standard security handler V5 / R6, AESV3), with strings and streams (metadata included) encrypted. --user-password is required to open the file; if it is empty, the file opens without one. --owner-password grants full access; if it is empty, a random owner password is used, so nobody can lift the restrictions. --permissions takes all (the default), none, or a list of print, print-hq, modify, copy, annotate, fill-forms, accessibility, assemble. Signing and encryption can be combined; the signature is computed over the encrypted file. Encrypted output is not byte-reproducible, because the file key, IVs and /ID are random. PDF/A does not allow encryption.

PDF/A and PDF/UA

Fields and signatures combine with the template's pdf settings (see pdf-standards.md):

Secrets

Values of --sign-password, --user-password and --owner-password can be env:NAME (read from an environment variable) or file:PATH (first line of a file). Plain values work but are visible in the process list. When a flag is omitted, the environment variables LIUSKA_SIGN_PASSWORD, LIUSKA_USER_PASSWORD and LIUSKA_OWNER_PASSWORD are used. If LIUSKA_USER_PASSWORD or LIUSKA_OWNER_PASSWORD is set, every render is encrypted.

render, batch and serve take the same flags. On the server they apply to POST /api/render; the PNG preview is never signed. One signing identity is used per process.

Library

key, chain, err := renderer.LoadPKCS12(p12Bytes, password)   // or renderer.LoadPEM(keyPEM, certPEM)
eng, _ := renderer.NewEngine(renderer.Options{
    Sign:    &renderer.SignOptions{Signer: key, Certificates: chain, Reason: "Approved", Field: "approver"},
    Encrypt: &renderer.EncryptOptions{UserPassword: "u", OwnerPassword: "o", Allow: "print,fill-forms"},
})

SignOptions.Signer is any crypto.Signer (RSA or ECDSA), so a key kept in an HSM or KMS can be wrapped instead of loaded from a file. SignOptions.HTTPClient and Time override the TSA client and the signing time.

Cost

These timings were measured on the development machine. A template without fields pays nothing extra. The examples/order-form-sized form page renders in about 0.1 ms. Signing adds about 0.06 ms with ECDSA P-256, about 0.6 ms with RSA-2048, plus the TSA round trip when a timestamp is requested. Encryption adds about 2 ms per document, almost all of it in the deliberately slow R6 password hash; the 23-page large.json takes about 6 ms in total.