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

Add PDF/UA subset #1485

Merged
merged 4 commits into from
Dec 17, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## pdfkit changelog

### Unreleased

- Add subset for PDF/UA

### [v0.14.0] - 2023-11-09

- Add support for PDF/A-1b, PDF/A-1a, PDF/A-2b, PDF/A-2a, PDF/A-3b, PDF/A-3a
Expand Down
2 changes: 2 additions & 0 deletions docs/accessibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Universal Accessibility) document (which is an extension of Tagged PDF):
* Pass the option `pdfVersion: '1.5'` (or a higher version) when creating your `PDFDocument`
(depending on the features you use, you may only need 1.4; refer to the PDF reference for
details).
* Pass the option `subset: 'PDF/UA'` when creating your `PDFDocument` (if you wish the PDF to
be identified as PDF/UA-1).
* Pass the option `tagged: true` when creating your `PDFDocument` (technically, this sets the
`Marked` property in the `Markings` dictionary to `true` in the PDF).
* Provide a `Title` in the `info` option, and pass `displayTitle: true` when creating your
Expand Down
24 changes: 24 additions & 0 deletions lib/mixins/pdfua.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

export default {

initPDFUA() {
this.subset = 1;
},

endSubset() {
this._addPdfuaMetadata();
},

_addPdfuaMetadata() {
this.appendXML(this._getPdfuaid());
},

_getPdfuaid() {
return `
<rdf:Description xmlns:pdfuaid="http://www.aiim.org/pdfua/ns/id/" rdf:about="">
<pdfuaid:part>${this.subset}</pdfuaid:part>
</rdf:Description>
`;
},

}
5 changes: 5 additions & 0 deletions lib/mixins/subsets.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import PDFA from './pdfa';
import PDFUA from './pdfua';

export default {
_importSubset(subset) {
Expand All @@ -20,6 +21,10 @@ export default {
this._importSubset(PDFA);
this.initPDFA(options.subset);
break;
case 'PDF/UA':
this._importSubset(PDFUA);
this.initPDFUA();
break;
}
}
}
37 changes: 37 additions & 0 deletions tests/unit/pdfua.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import PDFDocument from '../../lib/document';
import { logData } from './helpers';

describe('PDF/UA', () => {

test('metadata is present', () => {
let options = {
autoFirstPage: false,
pdfVersion: '1.7',
subset: 'PDF/UA',
tagged: true
};
let doc = new PDFDocument(options);
const data = logData(doc);
doc.end();
expect(data).toContainChunk([
`11 0 obj`,
`<<\n/length 841\n/Type /Metadata\n/Subtype /XML\n/Length 843\n>>`
]);
});

test('metadata constains pdfuaid part', () => {
let options = {
autoFirstPage: false,
pdfVersion: '1.7',
subset: 'PDF/UA',
tagged: true
};
let doc = new PDFDocument(options);
const data = logData(doc);
doc.end();
let metadata = Buffer.from(data[24]).toString();

expect(metadata).toContain('pdfuaid:part>1');
});

});