diff --git a/src/api/form/PDFCheckBox.ts b/src/api/form/PDFCheckBox.ts index 4da69f31f..c25b0559f 100644 --- a/src/api/form/PDFCheckBox.ts +++ b/src/api/form/PDFCheckBox.ts @@ -197,9 +197,11 @@ export default class PDFCheckBox extends PDFField { const widgets = this.acroField.getWidgets(); for (let idx = 0, len = widgets.length; idx < len; idx++) { const widget = widgets[idx]; - const value = this.acroField.getValue(); + const state = widget.getAppearanceState(); const normal = widget.getAppearances()?.normal; - return !(normal instanceof PDFDict && normal.has(value)); + + if (!(normal instanceof PDFDict)) return true; + if (state && !normal.has(state)) return true; } return false; diff --git a/src/api/form/PDFForm.ts b/src/api/form/PDFForm.ts index f2151b157..6fc3e3988 100644 --- a/src/api/form/PDFForm.ts +++ b/src/api/form/PDFForm.ts @@ -576,7 +576,8 @@ export default class PDFForm { } if (!(refOrDict instanceof PDFRef)) { - throw new Error(`Failed to extract appearance ref`); + const name = field.getName(); + throw new Error(`Failed to extract appearance ref for: ${name}`); } const xObjectKey = addRandomSuffix('FlatWidget', 10); diff --git a/src/api/form/PDFRadioGroup.ts b/src/api/form/PDFRadioGroup.ts index c4f897f50..40430e839 100644 --- a/src/api/form/PDFRadioGroup.ts +++ b/src/api/form/PDFRadioGroup.ts @@ -401,15 +401,14 @@ export default class PDFRadioGroup extends PDFField { const widgets = this.acroField.getWidgets(); for (let idx = 0, len = widgets.length; idx < len; idx++) { const widget = widgets[idx]; - const value = this.acroField.getValue(); + const state = widget.getAppearanceState(); const normal = widget.getAppearances()?.normal; - if (normal instanceof PDFDict && normal.has(value)) { - return false; - } + if (!(normal instanceof PDFDict)) return true; + if (state && !normal.has(state)) return true; } - return true; + return false; } /** diff --git a/src/core/annotation/PDFAnnotation.ts b/src/core/annotation/PDFAnnotation.ts index ef89b24a9..d62258251 100644 --- a/src/core/annotation/PDFAnnotation.ts +++ b/src/core/annotation/PDFAnnotation.ts @@ -39,6 +39,12 @@ class PDFAnnotation { this.dict.set(PDFName.of('Rect'), Rect); } + getAppearanceState(): PDFName | undefined { + const AS = this.dict.lookup(PDFName.of('AS')); + if (AS instanceof PDFName) return AS; + return undefined; + } + setAppearanceState(state: PDFName) { this.dict.set(PDFName.of('AS'), state); }