diff --git a/examples/kitchen-sink-accessible.pdf b/examples/kitchen-sink-accessible.pdf index d7ab8dd6..49b96e5f 100644 Binary files a/examples/kitchen-sink-accessible.pdf and b/examples/kitchen-sink-accessible.pdf differ diff --git a/lib/mixins/markings.js b/lib/mixins/markings.js index 589b7889..6a445368 100644 --- a/lib/mixins/markings.js +++ b/lib/mixins/markings.js @@ -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({ diff --git a/lib/page.js b/lib/page.js index 32b8dc58..de5fec0f 100644 --- a/lib/page.js +++ b/lib/page.js @@ -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(); diff --git a/tests/unit/markings.spec.js b/tests/unit/markings.spec.js index 845372f9..1fe81b8b 100644 --- a/tests/unit/markings.spec.js +++ b/tests/unit/markings.spec.js @@ -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` + ]); }); });