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
- Format: PAdES baseline B-B. The signature uses
/SubFilter /ETSI.CAdES.detached, a CMS SignedData with SHA-256, the signing certificate (plus chain) embedded, and the ESS signing-certificate-v2 attribute. It has no signing-time attribute; the time is in/M. Keys can be RSA or ECDSA. - Where: in the template signature field named by
--sign-field. Without the flag it goes in the first signature field. If the template has no signature field, the signature is invisible (a zero-size widget on page 1). A visible signature shows "Digitally signed by", the date, the reason and the location in the field's box and style. The name defaults to the certificate's common name; --sign-nameoverrides it. Naming a field that does not exist, or one that is hidden byvisibleIf, is an error. - Timestamp (B-T):
--tsa-urlasks an RFC 3161 TSA for a signature timestamp. It is off by default; when enabled, every render makes a network call. The token's message imprint and nonce are checked. - Unsigned signature fields stay empty and can be signed later in Acrobat or similar.
- Key files: PKCS#12 with OpenSSL 3 defaults (AES-256/PBKDF2) and legacy files (
-legacy, RC2/3DES), or unencrypted PEM (PKCS#8, PKCS#1, SEC 1). Encrypted PEM keys are rejected; use a PKCS#12 file with a password instead.
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):
- PDF/A-2/3 (b, u, a): documents with fields, and signed documents, validate with veraPDF. A signature is written in the same pass as the document, and its byte range covers the whole file except the signature value, which PDF/A allows.
- Encryption and PDF/A: PDF/A forbids encryption, so a render that combines
pdf.conformancewith encryption options fails with an error. - PDF/UA: every widget is put in the structure tree as a
Formelement at its place in reading order (header and footer widgets included). Every field gets a/TUaccessible name: thetooltip, else the signaturelabel, else the field name. Set a meaningfultooltipon every field. An encrypted PDF/UA document must allowaccessibilityin--permissions, otherwise the render fails.
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.