-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathpdfa.js
58 lines (50 loc) · 1.49 KB
/
pdfa.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import fs from 'fs';
export default {
initPDFA(pSubset) {
if (pSubset.charAt(pSubset.length - 3) === '-') {
this.subset_conformance = pSubset
.charAt(pSubset.length - 1)
.toUpperCase();
this.subset = parseInt(pSubset.charAt(pSubset.length - 2));
} else {
// Default to Basic conformance when user doesn't specify
this.subset_conformance = 'B';
this.subset = parseInt(pSubset.charAt(pSubset.length - 1));
}
},
endSubset() {
this._addPdfaMetadata();
this._addColorOutputIntent();
},
_addColorOutputIntent() {
const iccProfile = fs.readFileSync(
`${__dirname}/data/sRGB_IEC61966_2_1.icc`,
);
const colorProfileRef = this.ref({
Length: iccProfile.length,
N: 3,
});
colorProfileRef.write(iccProfile);
colorProfileRef.end();
const intentRef = this.ref({
Type: 'OutputIntent',
S: 'GTS_PDFA1',
Info: new String('sRGB IEC61966-2.1'),
OutputConditionIdentifier: new String('sRGB IEC61966-2.1'),
DestOutputProfile: colorProfileRef,
});
intentRef.end();
this._root.data.OutputIntents = [intentRef];
},
_getPdfaid() {
return `
<rdf:Description xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/" rdf:about="">
<pdfaid:part>${this.subset}</pdfaid:part>
<pdfaid:conformance>${this.subset_conformance}</pdfaid:conformance>
</rdf:Description>
`;
},
_addPdfaMetadata() {
this.appendXML(this._getPdfaid());
},
};