mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
Add PDF/UA subset (#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
This commit is contained in:
parent
5bbd9a18cb
commit
408dc4e9ba
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
24
lib/mixins/pdfua.js
Normal file
24
lib/mixins/pdfua.js
Normal file
@ -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>
|
||||
`;
|
||||
},
|
||||
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
import PDFA from './pdfa';
|
||||
import PDFUA from './pdfua';
|
||||
|
||||
export default {
|
||||
_importSubset(subset) {
|
||||
@ -20,6 +21,10 @@ export default {
|
||||
this._importSubset(PDFA);
|
||||
this.initPDFA(options.subset);
|
||||
break;
|
||||
case 'PDF/UA':
|
||||
this._importSubset(PDFUA);
|
||||
this.initPDFUA();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
tests/unit/pdfua.spec.js
Normal file
37
tests/unit/pdfua.spec.js
Normal file
@ -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');
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user