Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Update fontkit to 2.0
- Update linebreak to 1.1
- Add support for spot colors
- Fix sets tab order to "Structure" when a document is tagged
- Fix measuring text when OpenType features are passed in to .text()

### [v0.15.2] - 2024-12-15
Expand Down
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';
}
}

end() {
this._setTabOrder();
this.dictionary.end();
this.resources.data.ColorSpace = this.resources.data.ColorSpace || {};
for (let color of Object.values(this.document.spotColors)) {
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
Loading