Skip to content

Commit

Permalink
Add PDF/UA subset (#1485)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
andreiaugustin authored Dec 17, 2023
1 parent 5bbd9a1 commit 408dc4e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
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');
});

});

0 comments on commit 408dc4e

Please sign in to comment.