fix(form): remove widget refs from page Annots on removeField#1785
Open
cozminv wants to merge 1 commit into
Open
fix(form): remove widget refs from page Annots on removeField#1785cozminv wants to merge 1 commit into
cozminv wants to merge 1 commit into
Conversation
removeField() passed the appearance stream ref to removeAnnot(), not the widget annotation ref listed in the page /Annots array. Widget objects were deleted from the document while stale /Annots entries remained. Co-authored-by: Cursor <cursoragent@cursor.com>
Author
|
PR for #1784 |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Fix PDFForm.removeField() so it removes the widget annotation ref from each page's /Annots array, instead of passing an appearance-stream ref to removeAnnot().
Before (src/api/form/PDFForm.ts):
const widgetRef = this.findWidgetAppearanceRef(field, widget);
page.node.removeAnnot(widgetRef);
After:
const widgetRef = this.doc.context.getObjectRef(widget.dict);
if (widgetRef === undefined) {
throw new Error('Could not find PDFRef for widget annotation');
}
page.node.removeAnnot(widgetRef);
Added unit test "removes widget annotation refs from page Annots arrays" in tests/api/form/PDFForm.spec.ts.
Why?
removeField() currently calls page.node.removeAnnot() with the ref returned by findWidgetAppearanceRef() — an /AP/N appearance stream ref. Page /Annots arrays list widget annotation dict refs. PDFPageLeaf.removeAnnot() matches by exact PDFRef, so the widget entry is never removed. context.delete() then removes the widget object, leaving a dangling /Annots reference.
This was reported in #1001. PR #1002 fixed removal of child widget refs from the document context, but did not fix which ref is passed to removeAnnot().
Impact observed in a form-editor workflow (remove all fields, recreate them):
How?
For each widget returned by field.acroField.getWidgets():
Alternatives considered:
findWidgetAppearanceRef() is unchanged and remains used where appearance streams are needed (e.g. updateFieldAppearances, flatten).
Testing?
New Dependencies?
No
Screenshots
N/A — structural PDF fix; no visual appearance change in viewers when fields are removed correctly.
Suggested Reading?
Yes — PDF 32000 page annotations (/Annots) vs AcroForm field/widget structure; widget annotations use /Subtype /Widget and are listed on the page, separate from /AP appearance streams.
Anything Else?
Checklist