Skip to content

Commit 4700537

Browse files
authored
Fix for PDF accessibility check. (foliojs#1265)
1 parent 131df9e commit 4700537

2 files changed

Lines changed: 41 additions & 19 deletions

File tree

lib/mixins/markings.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export default {
1414
this.structChildren = [];
1515

1616
if (options.tagged) {
17-
this.getMarkingsDictionary().data.Marked = true;
17+
this.getMarkInfoDictionary().data.Marked = true;
18+
this.getStructTreeRoot();
1819
}
1920
},
2021

@@ -130,17 +131,17 @@ export default {
130131
return pageMarkings;
131132
},
132133

133-
getMarkingsDictionary() {
134-
if (!this._root.data.Markings) {
135-
this._root.data.Markings = this.ref({});
134+
getMarkInfoDictionary() {
135+
if (!this._root.data.MarkInfo) {
136+
this._root.data.MarkInfo = this.ref({});
136137
}
137-
return this._root.data.Markings;
138+
return this._root.data.MarkInfo;
138139
},
139140

140141
getStructTreeRoot() {
141142
if (!this._root.data.StructTreeRoot) {
142143
this._root.data.StructTreeRoot = this.ref({
143-
Type: "StructTreeRoot",
144+
Type: 'StructTreeRoot',
144145
ParentTree: new PDFNumberTree(),
145146
ParentTreeNextKey: 0
146147
});
@@ -153,8 +154,8 @@ export default {
153154
},
154155

155156
createStructParentTreeNextKey() {
156-
// initialise the Markings dictionary
157-
this.getMarkingsDictionary();
157+
// initialise the MarkInfo dictionary
158+
this.getMarkInfoDictionary();
158159

159160
const structTreeRoot = this.getStructTreeRoot();
160161
const key = structTreeRoot.data.ParentTreeNextKey++;
@@ -168,8 +169,8 @@ export default {
168169
structTreeRoot.end();
169170
this.structChildren.forEach((structElem) => structElem.end());
170171
}
171-
if (this._root.data.Markings) {
172-
this._root.data.Markings.end();
172+
if (this._root.data.MarkInfo) {
173+
this._root.data.MarkInfo.end();
173174
}
174175
}
175176

tests/unit/markings.spec.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ EMC
289289
]);
290290
expect(docData).toContainChunk([
291291
`3 0 obj`,
292-
/\/Markings 9 0 R/,
292+
/\/MarkInfo 9 0 R/,
293293
`endobj`
294294
]);
295295
expect(docData).toContainChunk([
@@ -369,7 +369,7 @@ EMC
369369
]);
370370
expect(docData).toContainChunk([
371371
`3 0 obj`,
372-
/\/Markings 9 0 R/,
372+
/\/MarkInfo 9 0 R/,
373373
`endobj`
374374
]);
375375
expect(docData).toContainChunk([
@@ -441,7 +441,7 @@ EMC
441441
]);
442442
expect(docData).toContainChunk([
443443
`3 0 obj`,
444-
/\/Markings 13 0 R/,
444+
/\/MarkInfo 13 0 R/,
445445
`endobj`
446446
]);
447447
expect(docData).toContainChunk([
@@ -569,7 +569,7 @@ EMC
569569
]);
570570
expect(docData).toContainChunk([
571571
`3 0 obj`,
572-
/\/Markings 5 0 R/,
572+
/\/MarkInfo 5 0 R/,
573573
`endobj`
574574
]);
575575
expect(docData).toContainChunk([
@@ -579,26 +579,47 @@ EMC
579579
]);
580580
expect(docData).toContainChunk([
581581
`3 0 obj`,
582-
/\/ViewerPreferences 6 0 R/,
582+
/\/ViewerPreferences 7 0 R/,
583583
`endobj`
584584
]);
585+
586+
expect(docData).toContainChunk([
587+
`3 0 obj`,
588+
/\/StructTreeRoot 6 0 R/,
589+
`endobj`
590+
]);
591+
585592
expect(docData).toContainChunk([
586593
`6 0 obj`,
594+
`<<
595+
/Type /StructTreeRoot
596+
/ParentTree <<
597+
/Nums [
598+
]
599+
>>
600+
/ParentTreeNextKey 0
601+
>>`,
602+
`endobj`
603+
]);
604+
605+
606+
expect(docData).toContainChunk([
607+
`7 0 obj`,
587608
/\/DisplayDocTitle true/,
588609
`endobj`
589610
]);
590611
expect(docData).toContainChunk([
591612
`trailer`,
592-
/\/Info 10 0 R/,
613+
/\/Info 11 0 R/,
593614
`startxref`
594615
]);
595616
expect(docData).toContainChunk([
596-
`10 0 obj`,
597-
/\/Title 14 0 R/,
617+
`11 0 obj`,
618+
/\/Title 15 0 R/,
598619
`endobj`
599620
]);
600621
expect(docData).toContainChunk([
601-
`14 0 obj`,
622+
`15 0 obj`,
602623
`(My Title)`,
603624
`endobj`
604625
]);

0 commit comments

Comments
 (0)