Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for PDF accessibility check. #1265

Merged
merged 2 commits into from Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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