Skip to content

Commit 408dc4e

Browse files
Add PDF/UA subset (foliojs#1485)
* Added PDF/UA subset and its metadata * Added PDF/UA metadata unit tests * Added PDF/UA subset to accessibility docs * Updated change log for PDF/UA subset
1 parent 5bbd9a1 commit 408dc4e

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## pdfkit changelog
22

3+
### Unreleased
4+
5+
- Add subset for PDF/UA
6+
37
### [v0.14.0] - 2023-11-09
48

59
- Add support for PDF/A-1b, PDF/A-1a, PDF/A-2b, PDF/A-2a, PDF/A-3b, PDF/A-3a

docs/accessibility.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Universal Accessibility) document (which is an extension of Tagged PDF):
1414
* Pass the option `pdfVersion: '1.5'` (or a higher version) when creating your `PDFDocument`
1515
(depending on the features you use, you may only need 1.4; refer to the PDF reference for
1616
details).
17+
* Pass the option `subset: 'PDF/UA'` when creating your `PDFDocument` (if you wish the PDF to
18+
be identified as PDF/UA-1).
1719
* Pass the option `tagged: true` when creating your `PDFDocument` (technically, this sets the
1820
`Marked` property in the `Markings` dictionary to `true` in the PDF).
1921
* Provide a `Title` in the `info` option, and pass `displayTitle: true` when creating your

lib/mixins/pdfua.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
export default {
3+
4+
initPDFUA() {
5+
this.subset = 1;
6+
},
7+
8+
endSubset() {
9+
this._addPdfuaMetadata();
10+
},
11+
12+
_addPdfuaMetadata() {
13+
this.appendXML(this._getPdfuaid());
14+
},
15+
16+
_getPdfuaid() {
17+
return `
18+
<rdf:Description xmlns:pdfuaid="http://www.aiim.org/pdfua/ns/id/" rdf:about="">
19+
<pdfuaid:part>${this.subset}</pdfuaid:part>
20+
</rdf:Description>
21+
`;
22+
},
23+
24+
}

lib/mixins/subsets.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import PDFA from './pdfa';
2+
import PDFUA from './pdfua';
23

34
export default {
45
_importSubset(subset) {
@@ -20,6 +21,10 @@ export default {
2021
this._importSubset(PDFA);
2122
this.initPDFA(options.subset);
2223
break;
24+
case 'PDF/UA':
25+
this._importSubset(PDFUA);
26+
this.initPDFUA();
27+
break;
2328
}
2429
}
2530
}

tests/unit/pdfua.spec.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import PDFDocument from '../../lib/document';
2+
import { logData } from './helpers';
3+
4+
describe('PDF/UA', () => {
5+
6+
test('metadata is present', () => {
7+
let options = {
8+
autoFirstPage: false,
9+
pdfVersion: '1.7',
10+
subset: 'PDF/UA',
11+
tagged: true
12+
};
13+
let doc = new PDFDocument(options);
14+
const data = logData(doc);
15+
doc.end();
16+
expect(data).toContainChunk([
17+
`11 0 obj`,
18+
`<<\n/length 841\n/Type /Metadata\n/Subtype /XML\n/Length 843\n>>`
19+
]);
20+
});
21+
22+
test('metadata constains pdfuaid part', () => {
23+
let options = {
24+
autoFirstPage: false,
25+
pdfVersion: '1.7',
26+
subset: 'PDF/UA',
27+
tagged: true
28+
};
29+
let doc = new PDFDocument(options);
30+
const data = logData(doc);
31+
doc.end();
32+
let metadata = Buffer.from(data[24]).toString();
33+
34+
expect(metadata).toContain('pdfuaid:part>1');
35+
});
36+
37+
});

0 commit comments

Comments
 (0)