Skip to content
Lamina PDF
0.9.0
GitHub
Open the web app

Check for an XFA form

You’ll check a PDF form for an XFA part. XFA is an older Adobe format, deprecated in PDF 2.0, that forms made in Adobe’s LiveCycle tools may carry. You need this before you fill a form, so you know what a person will see in each app.

xfaFacts says whether the form has an XFA part and what kind it is. xfa also gives each packet’s bytes. A dynamic form has placeholder pages, usually a message asking you to wait, and only Adobe’s apps can show or fill it. A static form has real pages and ordinary fields beside its XFA part. The example leaves a dynamic form alone and removes a static form’s XFA part with the removeXfa edit:

packages/sdk/examples/check-xfa-form.ts
// Check whether a PDF form is an XFA form, and make a static one show the same answers in every
// app. An XFA form is an older Adobe format that only Adobe's apps lay out. A dynamic one has
// placeholder pages and nothing to fill here; a static one has real pages and ordinary fields,
// but Adobe's apps show the XFA part's own answers, so the part is removed.
import { Document } from "@laminapdf/sdk";
/**
* The form as it saves: without its XFA part when it is a static XFA form, unchanged otherwise.
* Needs `init({ extract: true })`.
*/
export function checkXfaForm(form: Uint8Array): Uint8Array<ArrayBuffer> {
using doc = Document.open(form);
const xfa = doc.xfaFacts();
if (xfa === undefined) {
console.warn("not an XFA form");
} else if (xfa.kind === "dynamic") {
// Only Adobe's apps lay it out: leave it as it is.
console.warn("a dynamic XFA form: open it in Adobe Acrobat");
} else {
console.warn("a static XFA form: removing its XFA part");
doc.apply([{ op: "removeXfa", args: {} }]);
}
return doc.save({ mode: "fullRewrite" });
}
Page 1 of check_xfa_form.pdf
Open check_xfa_form.pdf (1 page, 691 bytes)

The saved form has the same pages and fields, and no XFA part.

  • A form is dynamic when the catalog’s /NeedsRendering is true, when its config packet requires dynamic rendering, or when its template has fields and its form has none. Any other form with an XFA part is static.
  • Adobe’s apps show a static form’s XFA answers, not the fields’, so answers filled into the fields alone don’t show there. Removing the XFA part makes every app show the fields.
  • Some static forms keep their answers only in the XFA part, so their fields look empty once it is gone. Undo brings the part back.
  • A certified file, and a file with usage rights, don’t allow the edit: saving it would change the file after the signature.

Next: fill a form from JSON.