PDFiumPas Docs

Encrypted typed AcroForm writes

Available in every edition since v3.249.0, updated 2026-11-04

SetFormFieldValue, SetFormFieldValues, their focused variants and the TPdfView facades support native AESV4 (V=6/R=7, AES-256-GCM), AESV3 Standard Security Handler R5/R6 documents and legacy R2/R3/R4 RC4/AESV2 documents within the existing typed field profile

Permission and security policy

The existing user-permission policy requires permFillForms or permModify, including when the document was opened using an owner credential; supplying an owner password does not bypass that policy

The transaction reuses the original file key, Encrypt dictionary, user and owner credential entries, permissions, metadata-encryption setting and first file ID; it encrypts changed object bodies before appending them to an encrypted snapshot

It does not replace passwords or silently downgrade to an unencrypted result; empty user passwords remain valid when already configured in the source security dictionary

Stream and string crypt filters must select the same supported method (AESV4, AESV3, crypt-filter V2 or AESV2), and any explicit embedded-file filter must select that filter too; unsupported or inconsistent crypt-filter configurations reject before replacing the live document; AESV4 needs the shipped pdfium build, because upstream pdfium reads AESV2/AESV3 only

Legacy R2/R3/R4 sources qualify with 40- to 128-bit RC4 keys and AESV2 128-bit keys derived from the original file key, first file ID and password padding per ISO 32000-1 algorithms 3.1 through 3.5; V1/V2 top-level and V4 crypt-filter key-length entries are validated against their documented bit and byte forms

Native AESV4/GCM field editing and authenticated-PDF-MAC form editing are not qualified by this profile; separate AESV4 context parsing remains supported by the cryptographic layer

Staging and publication

Plain field dictionaries are processed in bounded private memory; this encrypted field path does not use temporary-file stores for its plaintext staging

Private staging streams are cleared on release, whilst native parsing and ordinary in-process document data retain their existing memory lifecycle; this is not a guarantee that every native or allocator copy is securely erased

Source ciphertext and plaintext capture are capped at 64 MiB, staging and output at 128 MiB, and the ordinary field parser, input, promotion and work budgets still apply

New direct-field objects allocate above the encrypted snapshot's object-number range, and encrypted incremental writing refuses to overwrite the preserved Encrypt object

The exact encrypted candidate must pass strict native reopen with the same security revision, permissions and page count; all widget identities, values, flags, option labels, selections and button states must match the independently loaded planned plaintext candidate

Candidate widget verification permits 65536 widgets and 4194304 aggregate metadata/value characters; exhaustion rejects before publication

Read-only fields, late invalid requests, permission denial, unsupported security and candidate validation failures leave live source values and handles unchanged; failed requests report zero updated fields/widgets

Successful publication uses the existing document replacement workflow, invalidates old native handles/searches/selections, retains page and logical cursor state and suppresses automatic lifecycle actions

Active native focus still rejects before capture, preserving pending editor text and selection; signed sources follow the separate certification-aware profile (certification DocMDP permissions, FieldMDP and /Lock field policies), whilst XFA, ambiguous ownership and the existing unsupported field kinds remain rejected

Since v3.351.0, sources that are both signed and encrypted use the same policy profile; RC4 (40-128 bits), AESV2 and AESV3 sources take the same path, and the recorded acceptance qualifies RC4-128 and AES-128: the plaintext transaction is published as one sparse revision appended after the original encrypted bytes, each new object is sealed with the document key for its own object and generation number, and the trailer repeats the existing /Encrypt reference

The byte-exact original prefix keeps every recorded signature ByteRange segment intact, and the verification gates require strict reopen under the supplied password, unchanged security dictionary and revision, unchanged signature dictionaries and the updated field values; AESV4 sources remain unsupported because the deployed native library rejects them before a write can be staged

Example

Pdf.Password := 'user-password';
Pdf.FileName := 'secured.pdf';
Pdf.Active := True;
Pdf.PageNumber := 1;
Value := Default(TPdfFormValue);
Value.Kind := fvkText;
Value.Text := 'Updated value';
if not Pdf.SetFormFieldValue(0, Value, Report) then
  raise Exception.Create(Report.ErrorMessage);
if not Pdf.SaveAs('updated.pdf') then
  raise Exception.Create('Cannot save the encrypted document');

The ordinary save retains encryption; explicitly selecting saRemoveSecurity remains a separate caller decision