-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathmetadata.js
101 lines (87 loc) · 2.58 KB
/
metadata.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import PDFMetadata from '../metadata';
export default {
initMetadata() {
this.metadata = new PDFMetadata();
},
appendXML(xml, newline = true) {
this.metadata.append(xml, newline);
},
_addInfo() {
this.appendXML(`
<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">
<xmp:CreateDate>${this.info.CreationDate.toISOString().split('.')[0] + 'Z'}</xmp:CreateDate>
<xmp:CreatorTool>${this.info.Creator}</xmp:CreatorTool>
</rdf:Description>
`);
if (this.info.Title || this.info.Author || this.info.Subject) {
this.appendXML(`
<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
`);
if (this.info.Title) {
this.appendXML(`
<dc:title>
<rdf:Alt>
<rdf:li xml:lang="x-default">${this.info.Title}</rdf:li>
</rdf:Alt>
</dc:title>
`);
}
if (this.info.Author) {
this.appendXML(`
<dc:creator>
<rdf:Seq>
<rdf:li>${this.info.Author}</rdf:li>
</rdf:Seq>
</dc:creator>
`);
}
if (this.info.Subject) {
this.appendXML(`
<dc:description>
<rdf:Alt>
<rdf:li xml:lang="x-default">${this.info.Subject}</rdf:li>
</rdf:Alt>
</dc:description>
`);
}
this.appendXML(`
</rdf:Description>
`);
}
this.appendXML(
`
<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">
<pdf:Producer>${this.info.Creator}</pdf:Producer>`,
false,
);
if (this.info.Keywords) {
this.appendXML(
`
<pdf:Keywords>${this.info.Keywords}</pdf:Keywords>`,
false,
);
}
this.appendXML(`
</rdf:Description>
`);
},
endMetadata() {
this._addInfo();
this.metadata.end();
/*
Metadata was introduced in PDF 1.4, so adding it to 1.3
will likely only take up more space.
*/
if (this.version != 1.3) {
this.metadataRef = this.ref({
length: this.metadata.getLength(),
Type: 'Metadata',
Subtype: 'XML',
});
this.metadataRef.compress = false;
this.metadataRef.write(Buffer.from(this.metadata.getXML(), 'utf-8'));
this.metadataRef.end();
this._root.data.Metadata = this.metadataRef;
}
},
};