Skip to content

Commit

Permalink
Fix for PDF accessibility check. (#1265)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrift2000 committed Jun 22, 2021
1 parent 131df9e commit 4700537
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
21 changes: 11 additions & 10 deletions lib/mixins/markings.js
Expand Up @@ -14,7 +14,8 @@ export default {
this.structChildren = [];

if (options.tagged) {
this.getMarkingsDictionary().data.Marked = true;
this.getMarkInfoDictionary().data.Marked = true;
this.getStructTreeRoot();
}
},

Expand Down Expand Up @@ -130,17 +131,17 @@ export default {
return pageMarkings;
},

getMarkingsDictionary() {
if (!this._root.data.Markings) {
this._root.data.Markings = this.ref({});
getMarkInfoDictionary() {
if (!this._root.data.MarkInfo) {
this._root.data.MarkInfo = this.ref({});
}
return this._root.data.Markings;
return this._root.data.MarkInfo;
},

getStructTreeRoot() {
if (!this._root.data.StructTreeRoot) {
this._root.data.StructTreeRoot = this.ref({
Type: "StructTreeRoot",
Type: 'StructTreeRoot',
ParentTree: new PDFNumberTree(),
ParentTreeNextKey: 0
});
Expand All @@ -153,8 +154,8 @@ export default {
},

createStructParentTreeNextKey() {
// initialise the Markings dictionary
this.getMarkingsDictionary();
// initialise the MarkInfo dictionary
this.getMarkInfoDictionary();

const structTreeRoot = this.getStructTreeRoot();
const key = structTreeRoot.data.ParentTreeNextKey++;
Expand All @@ -168,8 +169,8 @@ export default {
structTreeRoot.end();
this.structChildren.forEach((structElem) => structElem.end());
}
if (this._root.data.Markings) {
this._root.data.Markings.end();
if (this._root.data.MarkInfo) {
this._root.data.MarkInfo.end();
}
}

Expand Down
39 changes: 30 additions & 9 deletions tests/unit/markings.spec.js
Expand Up @@ -289,7 +289,7 @@ EMC
]);
expect(docData).toContainChunk([
`3 0 obj`,
/\/Markings 9 0 R/,
/\/MarkInfo 9 0 R/,
`endobj`
]);
expect(docData).toContainChunk([
Expand Down Expand Up @@ -369,7 +369,7 @@ EMC
]);
expect(docData).toContainChunk([
`3 0 obj`,
/\/Markings 9 0 R/,
/\/MarkInfo 9 0 R/,
`endobj`
]);
expect(docData).toContainChunk([
Expand Down Expand Up @@ -441,7 +441,7 @@ EMC
]);
expect(docData).toContainChunk([
`3 0 obj`,
/\/Markings 13 0 R/,
/\/MarkInfo 13 0 R/,
`endobj`
]);
expect(docData).toContainChunk([
Expand Down Expand Up @@ -569,7 +569,7 @@ EMC
]);
expect(docData).toContainChunk([
`3 0 obj`,
/\/Markings 5 0 R/,
/\/MarkInfo 5 0 R/,
`endobj`
]);
expect(docData).toContainChunk([
Expand All @@ -579,26 +579,47 @@ EMC
]);
expect(docData).toContainChunk([
`3 0 obj`,
/\/ViewerPreferences 6 0 R/,
/\/ViewerPreferences 7 0 R/,
`endobj`
]);

expect(docData).toContainChunk([
`3 0 obj`,
/\/StructTreeRoot 6 0 R/,
`endobj`
]);

expect(docData).toContainChunk([
`6 0 obj`,
`<<
/Type /StructTreeRoot
/ParentTree <<
/Nums [
]
>>
/ParentTreeNextKey 0
>>`,
`endobj`
]);


expect(docData).toContainChunk([
`7 0 obj`,
/\/DisplayDocTitle true/,
`endobj`
]);
expect(docData).toContainChunk([
`trailer`,
/\/Info 10 0 R/,
/\/Info 11 0 R/,
`startxref`
]);
expect(docData).toContainChunk([
`10 0 obj`,
/\/Title 14 0 R/,
`11 0 obj`,
/\/Title 15 0 R/,
`endobj`
]);
expect(docData).toContainChunk([
`14 0 obj`,
`15 0 obj`,
`(My Title)`,
`endobj`
]);
Expand Down

0 comments on commit 4700537

Please sign in to comment.