-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Hey, ran into an issue when trying to fill the form fields in a tester PDF: 5E_CharacterSheet_Fillable.pdf. I debugged it with Opus 4.6 and it came up with a fix that works for me. Here's a report of what went wrong and how it was fixed, generated by the agent:
Version: @libpdf/core@0.3.3
In src/document/forms/acro-form.ts line 141:
const fieldsArray = this.dict.getArray("Fields");getArray("Fields") is called without a resolver. When /Fields is stored as a PdfRef (indirect object), getArray returns undefined because the value's type is "ref", not "array". The method returns [] and the form appears empty.
FieldTree.load() in src/document/forms/field-tree.ts line 69 does it correctly:
const fieldsArray = dict.getArray("Fields", resolve);Fix: Pass the resolver in AcroForm.getFields():
const fieldsArray = this.dict.getArray("Fields", this.registry.resolve.bind(this.registry));Consumer workaround: Resolve the indirect /Fields ref before using the form:
function patchIndirectFields(form: PDFForm) {
const acro = (form as any)._acroForm;
for (const [key, val] of acro.dict.entries) {
if (key.value === "Fields" && val.type === "ref") {
const resolved = acro.registry.resolve(val);
if (resolved?.type === "array") {
acro.dict.set("Fields", resolved);
acro.clearCache();
form.reloadFields();
}
break;
}
}
}Reproduction
Use the 5E_CharacterSheet_Fillable.pdf. Both its /Fields and page 2–3 /Contents entries are indirect references.