PdfFormFlattener class
Real form flattening: draws the appearance and deletes the field.
It is the missing delivery of phase F6 of the roadmap. The flattenFields()
of PdfAcroForm removes the /AcroForm without drawing anything — its
_flattenField is an empty skeleton — so the filled-in value disappears
from the page. Here the path is the PDFBox one (PDAcroForm.flatten):
- locate the widget in the
/Fieldstree, inheriting/FTand composing the fully qualified name; - take the form XObject of the normal appearance (
/AP /N), choosing the state by/ASwhen/Nis a dictionary of states; - draw that XObject on the page, scaled from the
/BBoxtransformed by the/Matrixup to the/Rectof the widget; - only then remove the widget from
/Annotsand the field from/AcroForm /Fields.
No appearance is synthesized. A field without a usable /AP /N raises
a warning and is not removed: claiming it was flattened without drawing
anything would lose the content silently (roadmap §9, "a flattened field
disappearing").
final document = PdfDocument.parseFromBytes(bytes);
final result = PdfFormFlattener(document).flatten();
print('${result.flattened.length} campos achatados');
print(result.warnings);
final flat = await document.save();
What the flattening covers
Any widget with a normal appearance, whatever the /FT: text, checkbox,
radio, button, combo, list and signature. What changes between them is only
the appearance already written, and that is what goes to the page. Fields
with /Kids are walked, and a widget with /AP /N in states picks the
state by /AS — that is how the mark of a checked checkbox is preserved.
What it does not cover
- Generating an appearance.
/NeedAppearances truewith a filled/Vand no/APdoes not become drawing; the field survives with a warning. That depends on thePdfAppearanceServiceplanned for F5/F6. /AP /Nin states without/AS. Picking a state would mean deciding for the document; the field survives with a warning.- XFA. A dynamic XFA form stays in the catalog; removing it is an explicit option planned for F6.
- Signatures. Flattening invalidates any existing signature, like any other content change.
Constructors
- PdfFormFlattener(PdfDocument document, {PdfFormFlattenOptions options = const PdfFormFlattenOptions()})
-
Creates the flattener for
document.
Properties
- acroForm ↔ PdfAcroFormAccess
-
The single path for changing the
/AcroForm.latefinal - document → PdfDocument
-
The edited document.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- mutator ↔ PdfLoadedObjectMutator
-
The materializer shared by every change of this operation.
latefinal
- options → PdfFormFlattenOptions
-
The flattening options.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- store → PdfObjectStore
-
The object resolution, with a fallback to the source parser.
final
Methods
-
flatten(
{Iterable< String> ? fieldNames}) → PdfFormFlattenResult - Flattens the form fields.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited