diff --git a/base/shared/annotation.js b/base/shared/annotation.js index 978a352..9a1cd7e 100755 --- a/base/shared/annotation.js +++ b/base/shared/annotation.js @@ -77,7 +77,7 @@ var Annotation = (function AnnotationClosure() { data.subtype = dict.get('Subtype').name; data.annotationFlags = dict.get('F'); - this.setRectangle(dict.get('Rect')); + this.getAndSetRectangle(dict); data.rect = this.rectangle; var color = dict.get('C'); @@ -117,7 +117,20 @@ var Annotation = (function AnnotationClosure() { } else { this.rectangle = [0, 0, 0, 0]; } - }, + }, + + getAndSetRectangle: function Annotation_getAndSetRectangle(dict) { + var rect = dict.get('Rect'); + var xref = dict.xref; + if (isArray(rect) && rect.length === 4) { + for (var i = 0; i < 4; i++) { + rect[i] = (typeof rect[i] === "object") ? xref.fetchIfRef(rect[i]) : rect[i]; + } + this.setRectangle(rect); + } else { + this.rectangle = [0, 0, 0, 0]; + } + }, getData: function Annotation_getData() { return this.data; @@ -330,9 +343,9 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() { var rawValue = Util.getInheritableProperty(dict, 'V') || ''; var value = (rawValue.name ? rawValue.name : rawValue) || ''; data.fieldValue = stringToPDFString(value); - + data.alternativeText = stringToPDFString(dict.get('TU') || ''); - + data.alternativeID = stringToPDFString(dict.get('TM') || ''); data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || ''; diff --git a/package.json b/package.json index 60cf682..9121cbb 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "test:jest": "jest --config ./jest.config.json", "test": "jest --config ./jest.config.json && npm run parse-r && npm run parse-fd", "test:forms": "cd ./test && sh p2j.forms.sh", - "test:misc": "cd ./test && sh p2j.one.sh misc . \"Expected: 13 success, 5 fail exception with stack trace\" ", + "test:misc": "cd ./test && sh p2j.one.sh misc . \"Expected: 14 success, 5 fail exception with stack trace\" ", "parse": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form", "parse-s": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s", "parse-t": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s -t", diff --git a/test/pdf/misc/i369_3fields.pdf b/test/pdf/misc/i369_3fields.pdf new file mode 100644 index 0000000..decc884 Binary files /dev/null and b/test/pdf/misc/i369_3fields.pdf differ