pdfkit 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -1
- package/js/data/sRGB_IEC61966_2_1.icc +0 -0
- package/js/pdfkit.es5.js +297 -107
- package/js/pdfkit.es5.js.map +1 -1
- package/js/pdfkit.esnext.js +215 -27
- package/js/pdfkit.esnext.js.map +1 -1
- package/js/pdfkit.js +256 -25
- package/js/pdfkit.js.map +1 -1
- package/js/pdfkit.standalone.js +1772 -2087
- package/package.json +8 -11
package/js/pdfkit.js
CHANGED
|
@@ -60,7 +60,9 @@ class PDFTree {
|
|
|
60
60
|
return out.join('\n');
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
_compareKeys()
|
|
63
|
+
_compareKeys()
|
|
64
|
+
/*a, b*/
|
|
65
|
+
{
|
|
64
66
|
throw new Error('Must be implemented by subclasses');
|
|
65
67
|
}
|
|
66
68
|
|
|
@@ -68,7 +70,9 @@ class PDFTree {
|
|
|
68
70
|
throw new Error('Must be implemented by subclasses');
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
_dataForKey()
|
|
73
|
+
_dataForKey()
|
|
74
|
+
/*k*/
|
|
75
|
+
{
|
|
72
76
|
throw new Error('Must be implemented by subclasses');
|
|
73
77
|
}
|
|
74
78
|
|
|
@@ -3286,6 +3290,14 @@ class EmbeddedFont extends PDFFont {
|
|
|
3286
3290
|
descriptor.data.FontFile2 = fontFile;
|
|
3287
3291
|
}
|
|
3288
3292
|
|
|
3293
|
+
if (this.document.subset) {
|
|
3294
|
+
const CIDSet = Buffer.from('FFFFFFFFC0', 'hex');
|
|
3295
|
+
const CIDSetRef = this.document.ref();
|
|
3296
|
+
CIDSetRef.write(CIDSet);
|
|
3297
|
+
CIDSetRef.end();
|
|
3298
|
+
descriptor.data.CIDSet = CIDSetRef;
|
|
3299
|
+
}
|
|
3300
|
+
|
|
3289
3301
|
descriptor.end();
|
|
3290
3302
|
const descendantFontData = {
|
|
3291
3303
|
Type: 'Font',
|
|
@@ -5032,18 +5044,29 @@ var OutlineMixin = {
|
|
|
5032
5044
|
|
|
5033
5045
|
};
|
|
5034
5046
|
|
|
5047
|
+
function _defineProperty(obj, key, value) {
|
|
5048
|
+
if (key in obj) {
|
|
5049
|
+
Object.defineProperty(obj, key, {
|
|
5050
|
+
value: value,
|
|
5051
|
+
enumerable: true,
|
|
5052
|
+
configurable: true,
|
|
5053
|
+
writable: true
|
|
5054
|
+
});
|
|
5055
|
+
} else {
|
|
5056
|
+
obj[key] = value;
|
|
5057
|
+
}
|
|
5058
|
+
|
|
5059
|
+
return obj;
|
|
5060
|
+
}
|
|
5061
|
+
|
|
5035
5062
|
function ownKeys(object, enumerableOnly) {
|
|
5036
5063
|
var keys = Object.keys(object);
|
|
5037
5064
|
|
|
5038
5065
|
if (Object.getOwnPropertySymbols) {
|
|
5039
5066
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
5044
|
-
});
|
|
5045
|
-
}
|
|
5046
|
-
|
|
5067
|
+
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
5068
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
5069
|
+
});
|
|
5047
5070
|
keys.push.apply(keys, symbols);
|
|
5048
5071
|
}
|
|
5049
5072
|
|
|
@@ -5070,21 +5093,6 @@ function _objectSpread2(target) {
|
|
|
5070
5093
|
return target;
|
|
5071
5094
|
}
|
|
5072
5095
|
|
|
5073
|
-
function _defineProperty(obj, key, value) {
|
|
5074
|
-
if (key in obj) {
|
|
5075
|
-
Object.defineProperty(obj, key, {
|
|
5076
|
-
value: value,
|
|
5077
|
-
enumerable: true,
|
|
5078
|
-
configurable: true,
|
|
5079
|
-
writable: true
|
|
5080
|
-
});
|
|
5081
|
-
} else {
|
|
5082
|
-
obj[key] = value;
|
|
5083
|
-
}
|
|
5084
|
-
|
|
5085
|
-
return obj;
|
|
5086
|
-
}
|
|
5087
|
-
|
|
5088
5096
|
/*
|
|
5089
5097
|
PDFStructureContent - a reference to a marked structure content
|
|
5090
5098
|
By Ben Schmidt
|
|
@@ -6061,6 +6069,219 @@ function isEqual(a, b) {
|
|
|
6061
6069
|
return a.Subtype === b.Subtype && a.Params.CheckSum.toString() === b.Params.CheckSum.toString() && a.Params.Size === b.Params.Size && a.Params.CreationDate === b.Params.CreationDate && a.Params.ModDate === b.Params.ModDate;
|
|
6062
6070
|
}
|
|
6063
6071
|
|
|
6072
|
+
var PDFA = {
|
|
6073
|
+
initPDFA(pSubset) {
|
|
6074
|
+
if (pSubset.charAt(pSubset.length - 3) === '-') {
|
|
6075
|
+
this.subset_conformance = pSubset.charAt(pSubset.length - 1).toUpperCase();
|
|
6076
|
+
this.subset = parseInt(pSubset.charAt(pSubset.length - 2));
|
|
6077
|
+
} else {
|
|
6078
|
+
// Default to Basic conformance when user doesn't specify
|
|
6079
|
+
this.subset_conformance = 'B';
|
|
6080
|
+
this.subset = parseInt(pSubset.charAt(pSubset.length - 1));
|
|
6081
|
+
}
|
|
6082
|
+
},
|
|
6083
|
+
|
|
6084
|
+
endSubset() {
|
|
6085
|
+
this._addPdfaMetadata();
|
|
6086
|
+
|
|
6087
|
+
const jsPath = `${__dirname}/data/sRGB_IEC61966_2_1.icc`;
|
|
6088
|
+
const jestPath = `${__dirname}/../color_profiles/sRGB_IEC61966_2_1.icc`;
|
|
6089
|
+
|
|
6090
|
+
this._addColorOutputIntent(fs.existsSync(jsPath) ? jsPath : jestPath);
|
|
6091
|
+
},
|
|
6092
|
+
|
|
6093
|
+
_addColorOutputIntent(pICCPath) {
|
|
6094
|
+
const iccProfile = fs.readFileSync(pICCPath);
|
|
6095
|
+
const colorProfileRef = this.ref({
|
|
6096
|
+
Length: iccProfile.length,
|
|
6097
|
+
N: 3
|
|
6098
|
+
});
|
|
6099
|
+
colorProfileRef.write(iccProfile);
|
|
6100
|
+
colorProfileRef.end();
|
|
6101
|
+
const intentRef = this.ref({
|
|
6102
|
+
Type: 'OutputIntent',
|
|
6103
|
+
S: 'GTS_PDFA1',
|
|
6104
|
+
Info: new String('sRGB IEC61966-2.1'),
|
|
6105
|
+
OutputConditionIdentifier: new String('sRGB IEC61966-2.1'),
|
|
6106
|
+
DestOutputProfile: colorProfileRef
|
|
6107
|
+
});
|
|
6108
|
+
intentRef.end();
|
|
6109
|
+
this._root.data.OutputIntents = [intentRef];
|
|
6110
|
+
},
|
|
6111
|
+
|
|
6112
|
+
_getPdfaid() {
|
|
6113
|
+
return `
|
|
6114
|
+
<rdf:Description xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/" rdf:about="">
|
|
6115
|
+
<pdfaid:part>${this.subset}</pdfaid:part>
|
|
6116
|
+
<pdfaid:conformance>${this.subset_conformance}</pdfaid:conformance>
|
|
6117
|
+
</rdf:Description>
|
|
6118
|
+
`;
|
|
6119
|
+
},
|
|
6120
|
+
|
|
6121
|
+
_addPdfaMetadata() {
|
|
6122
|
+
this.appendXML(this._getPdfaid());
|
|
6123
|
+
}
|
|
6124
|
+
|
|
6125
|
+
};
|
|
6126
|
+
|
|
6127
|
+
var SubsetMixin = {
|
|
6128
|
+
_importSubset(subset) {
|
|
6129
|
+
Object.assign(this, subset);
|
|
6130
|
+
},
|
|
6131
|
+
|
|
6132
|
+
initSubset(options) {
|
|
6133
|
+
switch (options.subset) {
|
|
6134
|
+
case 'PDF/A-1':
|
|
6135
|
+
case 'PDF/A-1a':
|
|
6136
|
+
case 'PDF/A-1b':
|
|
6137
|
+
case 'PDF/A-2':
|
|
6138
|
+
case 'PDF/A-2a':
|
|
6139
|
+
case 'PDF/A-2b':
|
|
6140
|
+
case 'PDF/A-3':
|
|
6141
|
+
case 'PDF/A-3a':
|
|
6142
|
+
case 'PDF/A-3b':
|
|
6143
|
+
this._importSubset(PDFA);
|
|
6144
|
+
|
|
6145
|
+
this.initPDFA(options.subset);
|
|
6146
|
+
break;
|
|
6147
|
+
}
|
|
6148
|
+
}
|
|
6149
|
+
|
|
6150
|
+
};
|
|
6151
|
+
|
|
6152
|
+
class PDFMetadata {
|
|
6153
|
+
constructor() {
|
|
6154
|
+
this._metadata = `
|
|
6155
|
+
<?xpacket begin="\ufeff" id="W5M0MpCehiHzreSzNTczkc9d"?>
|
|
6156
|
+
<x:xmpmeta xmlns:x="adobe:ns:meta/">
|
|
6157
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
|
6158
|
+
`;
|
|
6159
|
+
}
|
|
6160
|
+
|
|
6161
|
+
_closeTags() {
|
|
6162
|
+
this._metadata = this._metadata.concat(`
|
|
6163
|
+
</rdf:RDF>
|
|
6164
|
+
</x:xmpmeta>
|
|
6165
|
+
<?xpacket end="w"?>
|
|
6166
|
+
`);
|
|
6167
|
+
}
|
|
6168
|
+
|
|
6169
|
+
append(xml, newline = true) {
|
|
6170
|
+
this._metadata = this._metadata.concat(xml);
|
|
6171
|
+
if (newline) this._metadata = this._metadata.concat('\n');
|
|
6172
|
+
}
|
|
6173
|
+
|
|
6174
|
+
getXML() {
|
|
6175
|
+
return this._metadata;
|
|
6176
|
+
}
|
|
6177
|
+
|
|
6178
|
+
getLength() {
|
|
6179
|
+
return this._metadata.length;
|
|
6180
|
+
}
|
|
6181
|
+
|
|
6182
|
+
end() {
|
|
6183
|
+
this._closeTags();
|
|
6184
|
+
|
|
6185
|
+
this._metadata = this._metadata.trim();
|
|
6186
|
+
}
|
|
6187
|
+
|
|
6188
|
+
}
|
|
6189
|
+
|
|
6190
|
+
var MetadataMixin = {
|
|
6191
|
+
initMetadata() {
|
|
6192
|
+
this.metadata = new PDFMetadata();
|
|
6193
|
+
},
|
|
6194
|
+
|
|
6195
|
+
appendXML(xml, newline = true) {
|
|
6196
|
+
this.metadata.append(xml, newline);
|
|
6197
|
+
},
|
|
6198
|
+
|
|
6199
|
+
_addInfo() {
|
|
6200
|
+
this.appendXML(`
|
|
6201
|
+
<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">
|
|
6202
|
+
<xmp:CreateDate>${this.info.CreationDate.toISOString().split('.')[0] + "Z"}</xmp:CreateDate>
|
|
6203
|
+
<xmp:CreatorTool>${this.info.Creator}</xmp:CreatorTool>
|
|
6204
|
+
</rdf:Description>
|
|
6205
|
+
`);
|
|
6206
|
+
|
|
6207
|
+
if (this.info.Title || this.info.Author || this.info.Subject) {
|
|
6208
|
+
this.appendXML(`
|
|
6209
|
+
<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
|
6210
|
+
`);
|
|
6211
|
+
|
|
6212
|
+
if (this.info.Title) {
|
|
6213
|
+
this.appendXML(`
|
|
6214
|
+
<dc:title>
|
|
6215
|
+
<rdf:Alt>
|
|
6216
|
+
<rdf:li xml:lang="x-default">${this.info.Title}</rdf:li>
|
|
6217
|
+
</rdf:Alt>
|
|
6218
|
+
</dc:title>
|
|
6219
|
+
`);
|
|
6220
|
+
}
|
|
6221
|
+
|
|
6222
|
+
if (this.info.Author) {
|
|
6223
|
+
this.appendXML(`
|
|
6224
|
+
<dc:creator>
|
|
6225
|
+
<rdf:Seq>
|
|
6226
|
+
<rdf:li>${this.info.Author}</rdf:li>
|
|
6227
|
+
</rdf:Seq>
|
|
6228
|
+
</dc:creator>
|
|
6229
|
+
`);
|
|
6230
|
+
}
|
|
6231
|
+
|
|
6232
|
+
if (this.info.Subject) {
|
|
6233
|
+
this.appendXML(`
|
|
6234
|
+
<dc:description>
|
|
6235
|
+
<rdf:Alt>
|
|
6236
|
+
<rdf:li xml:lang="x-default">${this.info.Subject}</rdf:li>
|
|
6237
|
+
</rdf:Alt>
|
|
6238
|
+
</dc:description>
|
|
6239
|
+
`);
|
|
6240
|
+
}
|
|
6241
|
+
|
|
6242
|
+
this.appendXML(`
|
|
6243
|
+
</rdf:Description>
|
|
6244
|
+
`);
|
|
6245
|
+
}
|
|
6246
|
+
|
|
6247
|
+
this.appendXML(`
|
|
6248
|
+
<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">
|
|
6249
|
+
<pdf:Producer>${this.info.Creator}</pdf:Producer>`, false);
|
|
6250
|
+
|
|
6251
|
+
if (this.info.Keywords) {
|
|
6252
|
+
this.appendXML(`
|
|
6253
|
+
<pdf:Keywords>${this.info.Keywords}</pdf:Keywords>`, false);
|
|
6254
|
+
}
|
|
6255
|
+
|
|
6256
|
+
this.appendXML(`
|
|
6257
|
+
</rdf:Description>
|
|
6258
|
+
`);
|
|
6259
|
+
},
|
|
6260
|
+
|
|
6261
|
+
endMetadata() {
|
|
6262
|
+
this._addInfo();
|
|
6263
|
+
|
|
6264
|
+
this.metadata.end();
|
|
6265
|
+
/*
|
|
6266
|
+
Metadata was introduced in PDF 1.4, so adding it to 1.3
|
|
6267
|
+
will likely only take up more space.
|
|
6268
|
+
*/
|
|
6269
|
+
|
|
6270
|
+
if (this.version != 1.3) {
|
|
6271
|
+
this.metadataRef = this.ref({
|
|
6272
|
+
length: this.metadata.getLength(),
|
|
6273
|
+
Type: 'Metadata',
|
|
6274
|
+
Subtype: 'XML'
|
|
6275
|
+
});
|
|
6276
|
+
this.metadataRef.compress = false;
|
|
6277
|
+
this.metadataRef.write(Buffer.from(this.metadata.getXML(), 'utf-8'));
|
|
6278
|
+
this.metadataRef.end();
|
|
6279
|
+
this._root.data.Metadata = this.metadataRef;
|
|
6280
|
+
}
|
|
6281
|
+
}
|
|
6282
|
+
|
|
6283
|
+
};
|
|
6284
|
+
|
|
6064
6285
|
/*
|
|
6065
6286
|
PDFDocument - represents an entire PDF document
|
|
6066
6287
|
By Devon Govett
|
|
@@ -6124,13 +6345,15 @@ class PDFDocument extends stream.Readable {
|
|
|
6124
6345
|
|
|
6125
6346
|
this.page = null; // Initialize mixins
|
|
6126
6347
|
|
|
6348
|
+
this.initMetadata();
|
|
6127
6349
|
this.initColor();
|
|
6128
6350
|
this.initVector();
|
|
6129
6351
|
this.initFonts(options.font);
|
|
6130
6352
|
this.initText();
|
|
6131
6353
|
this.initImages();
|
|
6132
6354
|
this.initOutline();
|
|
6133
|
-
this.initMarkings(options);
|
|
6355
|
+
this.initMarkings(options);
|
|
6356
|
+
this.initSubset(options); // Initialize the metadata
|
|
6134
6357
|
|
|
6135
6358
|
this.info = {
|
|
6136
6359
|
Producer: 'PDFKit',
|
|
@@ -6351,6 +6574,12 @@ Please pipe the document into a Node stream.\
|
|
|
6351
6574
|
this.endOutline();
|
|
6352
6575
|
this.endMarkings();
|
|
6353
6576
|
|
|
6577
|
+
if (this.subset) {
|
|
6578
|
+
this.endSubset();
|
|
6579
|
+
}
|
|
6580
|
+
|
|
6581
|
+
this.endMetadata();
|
|
6582
|
+
|
|
6354
6583
|
this._root.end();
|
|
6355
6584
|
|
|
6356
6585
|
this._root.data.Pages.end();
|
|
@@ -6426,6 +6655,7 @@ const mixin = methods => {
|
|
|
6426
6655
|
Object.assign(PDFDocument.prototype, methods);
|
|
6427
6656
|
};
|
|
6428
6657
|
|
|
6658
|
+
mixin(MetadataMixin);
|
|
6429
6659
|
mixin(ColorMixin);
|
|
6430
6660
|
mixin(VectorMixin);
|
|
6431
6661
|
mixin(FontsMixin);
|
|
@@ -6436,6 +6666,7 @@ mixin(OutlineMixin);
|
|
|
6436
6666
|
mixin(MarkingsMixin);
|
|
6437
6667
|
mixin(AcroFormMixin);
|
|
6438
6668
|
mixin(AttachmentsMixin);
|
|
6669
|
+
mixin(SubsetMixin);
|
|
6439
6670
|
PDFDocument.LineWrapper = LineWrapper;
|
|
6440
6671
|
|
|
6441
6672
|
module.exports = PDFDocument;
|