Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 Object.prototype.hasOwnProperty.call(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';
}
}

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