Skip to content

Commit 49486ef

Browse files
authored
fix: #369: read value from xRef if rectangle coordinate is ref obj after dict.get('Rect') call (#380)
1 parent 5cbaa0f commit 49486ef

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

base/shared/annotation.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var Annotation = (function AnnotationClosure() {
7777

7878
data.subtype = dict.get('Subtype').name;
7979
data.annotationFlags = dict.get('F');
80-
this.setRectangle(dict.get('Rect'));
80+
this.getAndSetRectangle(dict);
8181
data.rect = this.rectangle;
8282

8383
var color = dict.get('C');
@@ -117,7 +117,20 @@ var Annotation = (function AnnotationClosure() {
117117
} else {
118118
this.rectangle = [0, 0, 0, 0];
119119
}
120-
},
120+
},
121+
122+
getAndSetRectangle: function Annotation_getAndSetRectangle(dict) {
123+
var rect = dict.get('Rect');
124+
var xref = dict.xref;
125+
if (isArray(rect) && rect.length === 4) {
126+
for (var i = 0; i < 4; i++) {
127+
rect[i] = (typeof rect[i] === "object") ? xref.fetchIfRef(rect[i]) : rect[i];
128+
}
129+
this.setRectangle(rect);
130+
} else {
131+
this.rectangle = [0, 0, 0, 0];
132+
}
133+
},
121134

122135
getData: function Annotation_getData() {
123136
return this.data;
@@ -330,9 +343,9 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() {
330343
var rawValue = Util.getInheritableProperty(dict, 'V') || '';
331344
var value = (rawValue.name ? rawValue.name : rawValue) || '';
332345
data.fieldValue = stringToPDFString(value);
333-
346+
334347
data.alternativeText = stringToPDFString(dict.get('TU') || '');
335-
348+
336349
data.alternativeID = stringToPDFString(dict.get('TM') || '');
337350

338351
data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"test:jest": "jest --config ./jest.config.json",
3838
"test": "jest --config ./jest.config.json && npm run parse-r && npm run parse-fd",
3939
"test:forms": "cd ./test && sh p2j.forms.sh",
40-
"test:misc": "cd ./test && sh p2j.one.sh misc . \"Expected: 13 success, 6 exceptions with stack trace\" ",
40+
"test:misc": "cd ./test && sh p2j.one.sh misc . \"Expected: 14 success, 5 fail exception with stack trace\" ",
4141
"parse": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form",
4242
"parse-s": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s",
4343
"parse-t": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s -t",

test/pdf/misc/i369_3fields.pdf

5.39 KB
Binary file not shown.

0 commit comments

Comments
 (0)