Skip to content

Flatten form fields

This operation removes interactive AcroForm fields from a PDF by writing their current values into page content via an iTextSharp PdfStamper with form flattening enabled.

Field Value
Operation ID OP-07
Trigger Caller invokes Flatten(byte[] file)
Inputs PDF bytes
Outputs Flattened PDF bytes, or the original bytes unchanged
Primary components PdfAPI.Core.PdfClientService.Flatten
Entry point PdfAPI.Core\Services\PdfClientService.cs

Steps

  1. Run Validate PDF bytes to guard the input. (BR-01, BR-02, BR-03)
  2. Open a PdfReader over the bytes.
  3. If reader.AcroForm is null, return the input bytes unchanged. (BR-11)
  4. Otherwise write through a PdfStamper with FormFlattening = true into a MemoryStream, close the stamper, and return the stream bytes. (BR-11)
  5. The MemoryStream in this step is not disposed and the PdfStamper is closed rather than disposed.*

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start(["Flatten(bytes)"]) --> Guard["OP-01: ValidatePdf"]
    Guard --> Open["Open PdfReader"]
    Open --> Form{reader.AcroForm null?}
    Form -->|Yes| Unchanged([Return original bytes])
    Form -->|No| Stamp["PdfStamper with<br>FormFlattening = true"]
    Stamp --> Return([Return flattened bytes])

Failure and edge-case behavior

  • A PDF without an AcroForm is returned byte-for-byte unchanged rather than being reprocessed (BR-11).

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.

Sources

  • PdfAPI.Core\Services\PdfClientService.cs