diff --git a/src/core/annotation.js b/src/core/annotation.js index aa312e157..54073b4c7 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -126,6 +126,8 @@ class AnnotationFactory { let subtype = dict.get("Subtype"); subtype = subtype instanceof Name ? subtype.name : null; + const acroFormDict = acroForm instanceof Dict ? acroForm : Dict.empty; + // Return the right annotation object based on the subtype and field type. const parameters = { xref, @@ -134,10 +136,12 @@ class AnnotationFactory { subtype, id, pdfManager, - acroForm: acroForm instanceof Dict ? acroForm : Dict.empty, + acroForm: acroFormDict, attachments, xfaDatasets, collectFields, + needAppearances: + !collectFields && acroFormDict.get("NeedAppearances") === true, pageIndex, }; @@ -508,6 +512,7 @@ class Annotation { } this._fallbackFontDict = null; + this._needAppearances = false; } /** @@ -1483,6 +1488,7 @@ class WidgetAnnotation extends Annotation { const dict = params.dict; const data = this.data; this.ref = params.ref; + this._needAppearances = params.needAppearances; data.annotationType = AnnotationType.WIDGET; if (data.fieldName === undefined) { @@ -1535,6 +1541,12 @@ class WidgetAnnotation extends Annotation { this._defaultAppearance ); + data.hasAppearance = + (this._needAppearances && + data.fieldValue !== undefined && + data.fieldValue !== null) || + data.hasAppearance; + const fieldType = getInheritableProperty({ dict, key: "FT" }); data.fieldType = fieldType instanceof Name ? fieldType.name : null; @@ -1909,18 +1921,25 @@ class WidgetAnnotation extends Annotation { rotation = storageEntry.rotation; } - if (rotation === undefined && value === undefined) { + if ( + rotation === undefined && + value === undefined && + !this._needAppearances + ) { if (!this._hasValueFromXFA || this.appearance) { // The annotation hasn't been rendered so use the appearance. return null; } } + // Empty or it has a trailing whitespace. + const colors = this.getBorderAndBackgroundAppearances(annotationStorage); + if (value === undefined) { // The annotation has its value in XFA datasets but not in the V field. value = this.data.fieldValue; if (!value) { - return ""; + return `/Tx BMC q ${colors}Q EMC`; } } @@ -1934,7 +1953,7 @@ class WidgetAnnotation extends Annotation { if (value === "") { // the field is empty: nothing to render - return ""; + return `/Tx BMC q ${colors}Q EMC`; } if (rotation === undefined) { @@ -2024,9 +2043,6 @@ class WidgetAnnotation extends Annotation { ); } - // Empty or it has a trailing whitespace. - const colors = this.getBorderAndBackgroundAppearances(annotationStorage); - if (alignment === 0 || alignment > 2) { // Left alignment: nothing to do return ( @@ -3020,18 +3036,21 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation { return super._getAppearance(evaluator, task, annotationStorage); } - if (!annotationStorage) { - return null; + let exportedValue, rotation; + const storageEntry = annotationStorage + ? annotationStorage.get(this.data.id) + : undefined; + + if (storageEntry) { + rotation = storageEntry.rotation; + exportedValue = storageEntry.value; } - const storageEntry = annotationStorage.get(this.data.id); - if (!storageEntry) { - return null; - } - - const rotation = storageEntry.rotation; - let exportedValue = storageEntry.value; - if (rotation === undefined && exportedValue === undefined) { + if ( + rotation === undefined && + exportedValue === undefined && + !this._needAppearances + ) { // The annotation hasn't been rendered so use the appearance return null; } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index dd308124f..64540ada1 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -548,3 +548,4 @@ !issue15340.pdf !bug1795263.pdf !issue15597.pdf +!bug1796741.pdf diff --git a/test/pdfs/bug1796741.pdf b/test/pdfs/bug1796741.pdf new file mode 100755 index 000000000..78973b03c Binary files /dev/null and b/test/pdfs/bug1796741.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index c782b5efa..b37283179 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -6960,5 +6960,12 @@ "md5": "af708acbb22c6c9d268240dcf4a39809", "rounds": 1, "type": "eq" + }, + { "id": "bug1796741-print", + "file": "pdfs/bug1796741.pdf", + "md5": "d5167d1b0d1b840c9aa258b98ce4fa62", + "rounds": 1, + "type": "eq", + "print": true } ]