From dcffcdabb2ab538821398366fd0a5ccd2f06eaac Mon Sep 17 00:00:00 2001 From: Adrian Rollett Date: Tue, 23 May 2023 17:51:57 -0600 Subject: [PATCH 1/4] Set tab order when document is tagged --- examples/kitchen-sink-accessible.pdf | Bin 659715 -> 661107 bytes lib/page.js | 13 ++++++++++--- tests/unit/markings.spec.js | 5 +++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/examples/kitchen-sink-accessible.pdf b/examples/kitchen-sink-accessible.pdf index d7ab8dd6973939a07914a2c36ee9f7e60e94a1cf..49b96e5f4726007dd78f766cd881511a3d3797a2 100644 GIT binary patch delta 2868 zcma)8&5Pq?7^gckuA3S0>enGeMhBsj_ak3#OuNW-N5vUkX9_Edhcta>CTyD2G~MYA zLcjq6nKm7aTa@*|;WcA>uf1doZTD<)HSL4d;<^JEbZ@-wmoS&W5Zmvia>4XxhF>?Of zm$eT!#xFjqJ(mVNJW7sbObC|L_MJYL)jgiLT{m$h^ zByubAh8d-a{J>uxYqC2@HP1g~p)RGFZ!Xv5Wvz|kr=-f-aKJxXz6()PIoAzTTl_W* z+}qJ@o?M9k(x^^G|EY}10`fAX%ZDV>JGZ{bjPw`IU+GxD1`G%l2gCu~z7eNUcj)oB znCJ;Q1&c|&@Hl6@C&q9yl#33hWp>NVH=I|B+lz;AWu0Vq6a1UpZR7gg+SeP!eJGpc z{KvaB|IHfx?)Nv&uRp3ie4$3aT6DsYmcwoS8Ce$fh4`0 zY9=Kz${snCrR*0Y&BC~X>82rK#KK6#C?QnDh()XMEZqXT&4t9sAk;9+&VUgOjZfF5 z%@s`a@x68FwM&*h{&ij2T{W;_j9=Q2?9^bQ8`Y|zD5YA(4v`8*3|5IpOkL0q)GTdM zyR;}CfQ(cODOo}Wv8(_k{S@nZ8N&!c^~xABC@D86g(!y3sL&0-ELu^bo2WuiH?%6I zqe^9T-4Hs77^7AyIx_~f5m+;ZE9GaFMk~G+)kVe3!lo#MS%gljmCj}t*dVLQ5Mgnw zm}Q_Urdib_x+d6RL=2cf-R-&Mu<-r6qsjc%JTJ yv#T>~dKQLh(p-+sj_10_HBrZH%KvZj>EvtFjgwK#4<$I6nu(;%&FdfRNdEyYPOD!4 delta 1486 zcmZuxziSjx5N4AYlShjD66{=r#B`bW=KUIT90)21f*2J+vA9bv5C}Oq4-uPHQ>3sG zi`7y)!9obKrQm;{h_(Mf3QeJn;^boD-8>hj*l)i#^L;aKcJIx?)~kiLzrOE`?tK{9 z`S@dLygHF(PaapVx3U|>r$O#b8Mn8ywH|S!58Pw&MNi{bNk;>nbYJSL4IX|T?kJv!Ayf>xJ z7EWjbkJbtgjG+-S7z3SP#*^p?OAA)`Vk{!|1~FnnqKRpL_n|mk5*{W|(dpjrwAPg8dqq*r&0V;1QT+jP0zpLp diff --git a/lib/page.js b/lib/page.js index 32b8dc58..5c27abee 100644 --- a/lib/page.js +++ b/lib/page.js @@ -98,13 +98,20 @@ class PDFPage { }); // The page dictionary - this.dictionary = this.document.ref({ + const pageDictionary = { Type: 'Page', Parent: this.document._root.data.Pages, MediaBox: [0, 0, this.width, this.height], Contents: this.content, - Resources: this.resources - }); + Resources: this.resources, + }; + + // Set tab order if document is tagged for accessibility. + if (this.document.getMarkInfoDictionary().data.Marked === true) { + pageDictionary.Tabs = 'S'; + } + + this.dictionary = this.document.ref(pageDictionary); this.markings = []; } diff --git a/tests/unit/markings.spec.js b/tests/unit/markings.spec.js index 845372f9..b9f576d1 100644 --- a/tests/unit/markings.spec.js +++ b/tests/unit/markings.spec.js @@ -623,6 +623,11 @@ EMC `(My Title)`, `endobj` ]); + expect(docData).toContainChunk([ + `10 0 obj`, + /\/Tabs \/S/, + `endobj` + ]); }); }); From 1c9ce2c941eeb1a7ae05ae3470cb3dcaa87808cd Mon Sep 17 00:00:00 2001 From: Adrian Rollett Date: Thu, 25 May 2023 15:30:43 -0600 Subject: [PATCH 2/4] Update approach and add inverse test --- lib/mixins/markings.js | 4 ++++ lib/page.js | 13 ++++++++----- tests/unit/markings.spec.js | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/lib/mixins/markings.js b/lib/mixins/markings.js index 589b7889..b6e81bbc 100644 --- a/lib/mixins/markings.js +++ b/lib/mixins/markings.js @@ -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({ diff --git a/lib/page.js b/lib/page.js index 5c27abee..960224c4 100644 --- a/lib/page.js +++ b/lib/page.js @@ -106,11 +106,6 @@ class PDFPage { Resources: this.resources, }; - // Set tab order if document is tagged for accessibility. - if (this.document.getMarkInfoDictionary().data.Marked === true) { - pageDictionary.Tabs = 'S'; - } - this.dictionary = this.document.ref(pageDictionary); this.markings = []; @@ -162,7 +157,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 b9f576d1..1fe81b8b 100644 --- a/tests/unit/markings.spec.js +++ b/tests/unit/markings.spec.js @@ -631,6 +631,42 @@ EMC }); }); + 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` + ]); + }); + }); + describe('text integration', () => { test('adds paragraphs to structure', () => { const docData = logData(document); From 3b82e0e26b2678698455edd1910f6be73d628baa Mon Sep 17 00:00:00 2001 From: Adrian Rollett Date: Thu, 25 May 2023 15:32:39 -0600 Subject: [PATCH 3/4] Revert page dictionary setup --- lib/page.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/page.js b/lib/page.js index 960224c4..de5fec0f 100644 --- a/lib/page.js +++ b/lib/page.js @@ -98,15 +98,13 @@ class PDFPage { }); // The page dictionary - const pageDictionary = { + this.dictionary = this.document.ref({ Type: 'Page', Parent: this.document._root.data.Pages, MediaBox: [0, 0, this.width, this.height], Contents: this.content, - Resources: this.resources, - }; - - this.dictionary = this.document.ref(pageDictionary); + Resources: this.resources + }); this.markings = []; } From 31b505ebe7dfd498a95f0706faebb9d6ffe3ca0c Mon Sep 17 00:00:00 2001 From: Adrian Rollett Date: Thu, 25 May 2023 19:35:39 -0600 Subject: [PATCH 4/4] Update lib/mixins/markings.js --- lib/mixins/markings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mixins/markings.js b/lib/mixins/markings.js index b6e81bbc..6a445368 100644 --- a/lib/mixins/markings.js +++ b/lib/mixins/markings.js @@ -139,7 +139,7 @@ export default { }, hasMarkInfoDictionary() { - return Object.prototype.hasOwnProperty.call(this._root.data, 'MarkInfo'); + return !!this._root.data.MarkInfo; }, getStructTreeRoot() {