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

Set tab order when document is tagged #1449

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified examples/kitchen-sink-accessible.pdf
Binary file not shown.
4 changes: 4 additions & 0 deletions lib/mixins/markings.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export default {
return this._root.data.MarkInfo;
},

hasMarkInfoDictionary() {
return !!this._root.data.MarkInfo;
},

getStructTreeRoot() {
if (!this._root.data.StructTreeRoot) {
this._root.data.StructTreeRoot = this.ref({
Expand Down
8 changes: 8 additions & 0 deletions lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,15 @@ class PDFPage {
return this.content.write(chunk);
}

// Set tab order if document is tagged for accessibility.
_setTabOrder() {
if (!this.dictionary.Tabs && this.document.hasMarkInfoDictionary()) {
this.dictionary.data.Tabs = 'S';
}
}
acrollet marked this conversation as resolved.
Show resolved Hide resolved

end() {
this._setTabOrder();
this.dictionary.end();
this.resources.end();
return this.content.end();
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/markings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,47 @@ EMC
`(My Title)`,
`endobj`
]);
expect(docData).toContainChunk([
`10 0 obj`,
/\/Tabs \/S/,
`endobj`
]);
});
});

describe('untagged document', () => {
test('taborder not set for unmarked content', () => {
document = new PDFDocument({
info: {
CreationDate: new Date(Date.UTC(2018, 1, 1)),
Title: "My Title"
},
displayTitle: true,
compress: false,
pdfVersion: '1.5',
tagged: false,
lang: 'en-AU'
});

const docData = logData(document);

document.end();

expect(docData).toContainChunk([
`3 0 obj`,
/\/Lang \(en-AU\)/,
`endobj`
]);
expect(docData).not.toContainChunk([
`3 0 obj`,
/\/MarkInfo 5 0 R/,
`endobj`
]);
expect(docData).not.toContainChunk([
`10 0 obj`,
/\/Tabs \/S/,
`endobj`
]);
});
});

Expand Down