@pdfme/pdf-lib 6.2.4 → 6.2.5
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/dist/core/crypto.d.ts +0 -1
- package/dist/core/embedders/CustomFontEmbedder.d.ts +13 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/objects/PDFHexString.d.ts +1 -0
- package/dist/core/objects/PDFString.d.ts +1 -0
- package/dist/core/parser/PDFObjectParser.d.ts +1 -0
- package/dist/core/parser/PDFParser.d.ts +4 -2
- package/dist/index.js +102 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/core/crypto.d.ts
CHANGED
|
@@ -68,7 +68,6 @@ declare class CipherTransform {
|
|
|
68
68
|
private StreamCipherConstructor;
|
|
69
69
|
constructor(stringCipherConstructor: () => Cipher, streamCipherConstructor: () => Cipher);
|
|
70
70
|
createStream(stream: StreamType, length: number): DecryptStream;
|
|
71
|
-
decryptString(s: string): string;
|
|
72
71
|
decryptBytes(d: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
73
72
|
encryptString(s: string): string;
|
|
74
73
|
}
|
|
@@ -3,6 +3,19 @@ import PDFHexString from '../objects/PDFHexString.js';
|
|
|
3
3
|
import PDFRef from '../objects/PDFRef.js';
|
|
4
4
|
import PDFContext from '../PDFContext.js';
|
|
5
5
|
import { Cache } from '../../utils/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Parses font bytes once per fontkit and byte range, and returns a new view of the parsed font on
|
|
8
|
+
* every call. Views share the directory and decoded tables (as fontkit's own `getVariation` does),
|
|
9
|
+
* but each has its own glyphs, layout engine and cmap processor: a glyph keeps the code points it
|
|
10
|
+
* was first created for, which go into the ToUnicode map, so sharing glyphs would let one
|
|
11
|
+
* document's text change another's, and keep every glyph ever created alive with the bytes.
|
|
12
|
+
* Bytes are looked up by their ArrayBuffer and range (embedFont wraps an ArrayBuffer in a new
|
|
13
|
+
* Uint8Array on every call), and reparsed if their leading bytes changed since.
|
|
14
|
+
*
|
|
15
|
+
* @internal Exported so that @pdfme/schemas measures text with the same parse that embedding
|
|
16
|
+
* uses; not meant to be called by applications.
|
|
17
|
+
*/
|
|
18
|
+
export declare const parseFont: (fontkit: Fontkit, fontData: Uint8Array) => Font;
|
|
6
19
|
/**
|
|
7
20
|
* A note of thanks to the developers of https://github.com/foliojs/pdfkit, as
|
|
8
21
|
* this class borrows from:
|
package/dist/core/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { default as PDFTrailer } from './document/PDFTrailer.js';
|
|
|
9
9
|
export { default as PDFTrailerDict } from './document/PDFTrailerDict.js';
|
|
10
10
|
export { default as PDFCrossRefSection } from './document/PDFCrossRefSection.js';
|
|
11
11
|
export { default as StandardFontEmbedder } from './embedders/StandardFontEmbedder.js';
|
|
12
|
-
export { default as CustomFontEmbedder } from './embedders/CustomFontEmbedder.js';
|
|
12
|
+
export { default as CustomFontEmbedder, parseFont } from './embedders/CustomFontEmbedder.js';
|
|
13
13
|
export { default as CustomFontSubsetEmbedder } from './embedders/CustomFontSubsetEmbedder.js';
|
|
14
14
|
export { default as FileEmbedder, AFRelationship } from './embedders/FileEmbedder.js';
|
|
15
15
|
export { default as JpegEmbedder } from './embedders/JpegEmbedder.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import PDFObject from './PDFObject.js';
|
|
2
2
|
declare class PDFHexString extends PDFObject {
|
|
3
3
|
static of: (value: string) => PDFHexString;
|
|
4
|
+
static fromBytes: (bytes: Uint8Array) => PDFHexString;
|
|
4
5
|
static fromText: (value: string) => PDFHexString;
|
|
5
6
|
private readonly value;
|
|
6
7
|
constructor(value: string);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import PDFObject from './PDFObject.js';
|
|
2
2
|
declare class PDFString extends PDFObject {
|
|
3
3
|
static of: (value: string) => PDFString;
|
|
4
|
+
static fromBytes: (bytes: Uint8Array) => PDFString;
|
|
4
5
|
static fromDate: (date: Date) => PDFString;
|
|
5
6
|
private readonly value;
|
|
6
7
|
private constructor();
|
|
@@ -26,6 +26,7 @@ declare class PDFObjectParser extends BaseParser {
|
|
|
26
26
|
protected parseArray(ref?: PDFRef): PDFArray;
|
|
27
27
|
protected parseDict(ref?: PDFRef): PDFDict;
|
|
28
28
|
protected parseDictOrStream(ref?: PDFRef): PDFDict | PDFStream;
|
|
29
|
+
private decrypt;
|
|
29
30
|
protected findEndOfStreamFallback(startPos: Position): number;
|
|
30
31
|
}
|
|
31
32
|
export default PDFObjectParser;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import PDFRef from '../objects/PDFRef.js';
|
|
1
2
|
import PDFObjectParser from './PDFObjectParser.js';
|
|
2
3
|
import PDFContext from '../PDFContext.js';
|
|
3
4
|
import { CipherTransformFactory } from '../crypto.js';
|
|
4
5
|
declare class PDFParser extends PDFObjectParser {
|
|
5
|
-
static forBytesWithOptions: (pdfBytes: Uint8Array, objectsPerTick?: number, throwOnInvalidObject?: boolean, capNumbers?: boolean, cryptoFactory?: CipherTransformFactory) => PDFParser;
|
|
6
|
+
static forBytesWithOptions: (pdfBytes: Uint8Array, objectsPerTick?: number, throwOnInvalidObject?: boolean, capNumbers?: boolean, cryptoFactory?: CipherTransformFactory, encryptRef?: PDFRef) => PDFParser;
|
|
6
7
|
private readonly objectsPerTick;
|
|
7
8
|
private readonly throwOnInvalidObject;
|
|
9
|
+
private readonly encryptRef?;
|
|
8
10
|
private alreadyParsed;
|
|
9
11
|
private parsedObjects;
|
|
10
|
-
constructor(pdfBytes: Uint8Array, objectsPerTick?: number, throwOnInvalidObject?: boolean, capNumbers?: boolean, cryptoFactory?: CipherTransformFactory);
|
|
12
|
+
constructor(pdfBytes: Uint8Array, objectsPerTick?: number, throwOnInvalidObject?: boolean, capNumbers?: boolean, cryptoFactory?: CipherTransformFactory, encryptRef?: PDFRef);
|
|
11
13
|
parseDocument(): Promise<PDFContext>;
|
|
12
14
|
private maybeRecoverRoot;
|
|
13
15
|
private parseHeader;
|
package/dist/index.js
CHANGED
|
@@ -3084,6 +3084,11 @@ var PDFHexString = class PDFHexString extends PDFObject {
|
|
|
3084
3084
|
};
|
|
3085
3085
|
_PDFHexString = PDFHexString;
|
|
3086
3086
|
_defineProperty(PDFHexString, "of", (value) => new _PDFHexString(value));
|
|
3087
|
+
_defineProperty(PDFHexString, "fromBytes", (bytes) => {
|
|
3088
|
+
let hex = "";
|
|
3089
|
+
for (let idx = 0, len = bytes.length; idx < len; idx++) hex += toHexString(bytes[idx]);
|
|
3090
|
+
return new _PDFHexString(hex);
|
|
3091
|
+
});
|
|
3087
3092
|
_defineProperty(PDFHexString, "fromText", (value) => {
|
|
3088
3093
|
const encoded = utf16Encode(value);
|
|
3089
3094
|
let hex = "";
|
|
@@ -3272,15 +3277,17 @@ var PDFString = class PDFString extends PDFObject {
|
|
|
3272
3277
|
if (byte === CharCodes.BackSlash) escaped = true;
|
|
3273
3278
|
else pushByte(byte);
|
|
3274
3279
|
} else if (byte === CharCodes.Newline) pushByte();
|
|
3275
|
-
else if (byte === CharCodes.CarriageReturn)
|
|
3276
|
-
|
|
3280
|
+
else if (byte === CharCodes.CarriageReturn) {
|
|
3281
|
+
if (nextChar === "\n") idx++;
|
|
3282
|
+
pushByte();
|
|
3283
|
+
} else if (byte === CharCodes.n) pushByte(CharCodes.Newline);
|
|
3277
3284
|
else if (byte === CharCodes.r) pushByte(CharCodes.CarriageReturn);
|
|
3278
3285
|
else if (byte === CharCodes.t) pushByte(CharCodes.Tab);
|
|
3279
3286
|
else if (byte === CharCodes.b) pushByte(CharCodes.Backspace);
|
|
3280
3287
|
else if (byte === CharCodes.f) pushByte(CharCodes.FormFeed);
|
|
3281
3288
|
else if (byte === CharCodes.LeftParen) pushByte(CharCodes.LeftParen);
|
|
3282
3289
|
else if (byte === CharCodes.RightParen) pushByte(CharCodes.RightParen);
|
|
3283
|
-
else if (byte === CharCodes.
|
|
3290
|
+
else if (byte === CharCodes.BackSlash) pushByte(CharCodes.BackSlash);
|
|
3284
3291
|
else if (byte >= CharCodes.Zero && byte <= CharCodes.Seven) {
|
|
3285
3292
|
octal += char;
|
|
3286
3293
|
if (octal.length === 3 || !(nextChar >= "0" && nextChar <= "7")) {
|
|
@@ -3323,6 +3330,18 @@ var PDFString = class PDFString extends PDFObject {
|
|
|
3323
3330
|
};
|
|
3324
3331
|
_PDFString = PDFString;
|
|
3325
3332
|
_defineProperty(PDFString, "of", (value) => new _PDFString(value));
|
|
3333
|
+
_defineProperty(PDFString, "fromBytes", (bytes) => {
|
|
3334
|
+
let value = "";
|
|
3335
|
+
for (let idx = 0, len = bytes.length; idx < len; idx++) {
|
|
3336
|
+
const byte = bytes[idx];
|
|
3337
|
+
if (byte === CharCodes.LeftParen) value += "\\(";
|
|
3338
|
+
else if (byte === CharCodes.RightParen) value += "\\)";
|
|
3339
|
+
else if (byte === CharCodes.BackSlash) value += "\\\\";
|
|
3340
|
+
else if (byte === CharCodes.CarriageReturn) value += "\\r";
|
|
3341
|
+
else value += charFromCode(byte);
|
|
3342
|
+
}
|
|
3343
|
+
return new _PDFString(value);
|
|
3344
|
+
});
|
|
3326
3345
|
_defineProperty(PDFString, "fromDate", (date) => {
|
|
3327
3346
|
const year = padStart(String(date.getUTCFullYear()), 4, "0");
|
|
3328
3347
|
const month = padStart(String(date.getUTCMonth() + 1), 2, "0");
|
|
@@ -3335,13 +3354,67 @@ _defineProperty(PDFString, "fromDate", (date) => {
|
|
|
3335
3354
|
//#endregion
|
|
3336
3355
|
//#region src/core/embedders/CustomFontEmbedder.ts
|
|
3337
3356
|
/**
|
|
3357
|
+
* How many leading bytes are compared to tell whether a cached font's bytes were overwritten in
|
|
3358
|
+
* place. They cover the table directory, whose per-table checksums change with the font. This is
|
|
3359
|
+
* a best-effort check, not a full comparison: bytes rewritten past this point with an unchanged
|
|
3360
|
+
* directory would reuse the old parse.
|
|
3361
|
+
*/
|
|
3362
|
+
var FINGERPRINT_LENGTH = 1024;
|
|
3363
|
+
var parsedFonts = /* @__PURE__ */ new WeakMap();
|
|
3364
|
+
var sameBytes = (a, b) => a.length === b.length && a.every((byte, idx) => byte === b[idx]);
|
|
3365
|
+
var hasGlyphCache = (font) => typeof font._glyphs === "object";
|
|
3366
|
+
var createView = (font) => {
|
|
3367
|
+
const view = Object.create(font);
|
|
3368
|
+
view._glyphs = {};
|
|
3369
|
+
return view;
|
|
3370
|
+
};
|
|
3371
|
+
/**
|
|
3372
|
+
* Parses font bytes once per fontkit and byte range, and returns a new view of the parsed font on
|
|
3373
|
+
* every call. Views share the directory and decoded tables (as fontkit's own `getVariation` does),
|
|
3374
|
+
* but each has its own glyphs, layout engine and cmap processor: a glyph keeps the code points it
|
|
3375
|
+
* was first created for, which go into the ToUnicode map, so sharing glyphs would let one
|
|
3376
|
+
* document's text change another's, and keep every glyph ever created alive with the bytes.
|
|
3377
|
+
* Bytes are looked up by their ArrayBuffer and range (embedFont wraps an ArrayBuffer in a new
|
|
3378
|
+
* Uint8Array on every call), and reparsed if their leading bytes changed since.
|
|
3379
|
+
*
|
|
3380
|
+
* @internal Exported so that @pdfme/schemas measures text with the same parse that embedding
|
|
3381
|
+
* uses; not meant to be called by applications.
|
|
3382
|
+
*/
|
|
3383
|
+
var parseFont = (fontkit, fontData) => {
|
|
3384
|
+
let fontsByBuffer = parsedFonts.get(fontkit.create);
|
|
3385
|
+
if (!fontsByBuffer) {
|
|
3386
|
+
fontsByBuffer = /* @__PURE__ */ new WeakMap();
|
|
3387
|
+
parsedFonts.set(fontkit.create, fontsByBuffer);
|
|
3388
|
+
}
|
|
3389
|
+
let fonts = fontsByBuffer.get(fontData.buffer);
|
|
3390
|
+
if (!fonts) {
|
|
3391
|
+
fonts = [];
|
|
3392
|
+
fontsByBuffer.set(fontData.buffer, fonts);
|
|
3393
|
+
}
|
|
3394
|
+
const { byteOffset, byteLength } = fontData;
|
|
3395
|
+
const fingerprint = fontData.subarray(0, FINGERPRINT_LENGTH);
|
|
3396
|
+
const idx = fonts.findIndex((f) => f.byteOffset === byteOffset && f.byteLength === byteLength);
|
|
3397
|
+
if (idx !== -1 && sameBytes(fonts[idx].fingerprint, fingerprint)) return createView(fonts[idx].font);
|
|
3398
|
+
const font = fontkit.create(fontData);
|
|
3399
|
+
if (!hasGlyphCache(font)) return font;
|
|
3400
|
+
const parsed = {
|
|
3401
|
+
byteOffset,
|
|
3402
|
+
byteLength,
|
|
3403
|
+
fingerprint: fingerprint.slice(),
|
|
3404
|
+
font
|
|
3405
|
+
};
|
|
3406
|
+
if (idx === -1) fonts.push(parsed);
|
|
3407
|
+
else fonts[idx] = parsed;
|
|
3408
|
+
return createView(font);
|
|
3409
|
+
};
|
|
3410
|
+
/**
|
|
3338
3411
|
* A note of thanks to the developers of https://github.com/foliojs/pdfkit, as
|
|
3339
3412
|
* this class borrows from:
|
|
3340
3413
|
* https://github.com/devongovett/pdfkit/blob/e71edab0dd4657b5a767804ba86c94c58d01fbca/lib/image/jpeg.coffee
|
|
3341
3414
|
*/
|
|
3342
3415
|
var CustomFontEmbedder = class CustomFontEmbedder {
|
|
3343
3416
|
static async for(fontkit, fontData, customName, fontFeatures) {
|
|
3344
|
-
const font = fontkit
|
|
3417
|
+
const font = parseFont(fontkit, fontData);
|
|
3345
3418
|
return new CustomFontEmbedder(font, fontData, customName, fontFeatures);
|
|
3346
3419
|
}
|
|
3347
3420
|
constructor(font, fontData, customName, fontFeatures) {
|
|
@@ -3550,7 +3623,7 @@ var CustomFontEmbedder = class CustomFontEmbedder {
|
|
|
3550
3623
|
*/
|
|
3551
3624
|
var CustomFontSubsetEmbedder = class CustomFontSubsetEmbedder extends CustomFontEmbedder {
|
|
3552
3625
|
static async for(fontkit, fontData, customFontName, fontFeatures) {
|
|
3553
|
-
const font = fontkit
|
|
3626
|
+
const font = parseFont(fontkit, fontData);
|
|
3554
3627
|
return new CustomFontSubsetEmbedder(font, fontData, customFontName, fontFeatures);
|
|
3555
3628
|
}
|
|
3556
3629
|
constructor(font, fontData, customFontName, fontFeatures) {
|
|
@@ -3641,7 +3714,7 @@ var FileEmbedder = class FileEmbedder {
|
|
|
3641
3714
|
const embeddedFileStreamRef = context.register(embeddedFileStream);
|
|
3642
3715
|
const fileSpecDict = context.obj({
|
|
3643
3716
|
Type: "Filespec",
|
|
3644
|
-
F: PDFString.
|
|
3717
|
+
F: PDFString.fromBytes(stringAsByteArray(this.fileName)),
|
|
3645
3718
|
UF: PDFHexString.fromText(this.fileName),
|
|
3646
3719
|
EF: { F: embeddedFileStreamRef },
|
|
3647
3720
|
Desc: description ? PDFHexString.fromText(description) : void 0,
|
|
@@ -7275,7 +7348,7 @@ var PDFObjectParser = class extends BaseParser {
|
|
|
7275
7348
|
this.bytes.assertNext(CharCodes.LessThan);
|
|
7276
7349
|
while (!this.bytes.done() && this.bytes.peek() !== CharCodes.GreaterThan) value += charFromCode(this.bytes.next());
|
|
7277
7350
|
this.bytes.assertNext(CharCodes.GreaterThan);
|
|
7278
|
-
if (this.cryptoFactory && ref)
|
|
7351
|
+
if (this.cryptoFactory && ref) return PDFHexString.fromBytes(this.decrypt(PDFHexString.of(value).asBytes(), ref));
|
|
7279
7352
|
return PDFHexString.of(value);
|
|
7280
7353
|
}
|
|
7281
7354
|
parseString(ref) {
|
|
@@ -7292,8 +7365,8 @@ var PDFObjectParser = class extends BaseParser {
|
|
|
7292
7365
|
if (byte === CharCodes.BackSlash) isEscaped = !isEscaped;
|
|
7293
7366
|
else if (isEscaped) isEscaped = false;
|
|
7294
7367
|
if (nestingLvl === 0) {
|
|
7295
|
-
|
|
7296
|
-
if (this.cryptoFactory && ref)
|
|
7368
|
+
const actualValue = value.substring(1, value.length - 1);
|
|
7369
|
+
if (this.cryptoFactory && ref) return PDFString.fromBytes(this.decrypt(PDFString.of(actualValue).asBytes(), ref));
|
|
7297
7370
|
return PDFString.of(actualValue);
|
|
7298
7371
|
}
|
|
7299
7372
|
}
|
|
@@ -7344,7 +7417,7 @@ var PDFObjectParser = class extends BaseParser {
|
|
|
7344
7417
|
}
|
|
7345
7418
|
parseDictOrStream(ref) {
|
|
7346
7419
|
const startPos = this.bytes.position();
|
|
7347
|
-
|
|
7420
|
+
let dict = this.parseDict(ref);
|
|
7348
7421
|
this.skipWhitespaceAndComments();
|
|
7349
7422
|
if (!this.matchKeyword(Keywords.streamEOF1) && !this.matchKeyword(Keywords.streamEOF2) && !this.matchKeyword(Keywords.streamEOF3) && !this.matchKeyword(Keywords.streamEOF4) && !this.matchKeyword(Keywords.stream)) return dict;
|
|
7350
7423
|
const start = this.bytes.offset();
|
|
@@ -7360,9 +7433,19 @@ var PDFObjectParser = class extends BaseParser {
|
|
|
7360
7433
|
}
|
|
7361
7434
|
} else end = this.findEndOfStreamFallback(startPos);
|
|
7362
7435
|
let contents = this.bytes.slice(start, end);
|
|
7363
|
-
if (this.cryptoFactory && ref)
|
|
7436
|
+
if (this.cryptoFactory && ref) {
|
|
7437
|
+
if (dict.get(PDFName.of("Type")) === PDFName.of("XRef")) {
|
|
7438
|
+
const afterStream = this.bytes.offset();
|
|
7439
|
+
this.bytes.moveTo(startPos.offset);
|
|
7440
|
+
dict = this.parseDict();
|
|
7441
|
+
this.bytes.moveTo(afterStream);
|
|
7442
|
+
} else contents = this.decrypt(contents, ref);
|
|
7443
|
+
}
|
|
7364
7444
|
return PDFRawStream.of(dict, contents);
|
|
7365
7445
|
}
|
|
7446
|
+
decrypt(bytes, ref) {
|
|
7447
|
+
return this.cryptoFactory.createCipherTransform(ref.objectNumber, ref.generationNumber).decryptBytes(bytes);
|
|
7448
|
+
}
|
|
7366
7449
|
findEndOfStreamFallback(startPos) {
|
|
7367
7450
|
let nestingLvl = 1;
|
|
7368
7451
|
let end = this.bytes.offset();
|
|
@@ -7508,10 +7591,11 @@ _defineProperty(PDFXRefStreamParser, "forStream", (rawStream) => new _PDFXRefStr
|
|
|
7508
7591
|
//#region src/core/parser/PDFParser.ts
|
|
7509
7592
|
var _PDFParser;
|
|
7510
7593
|
var PDFParser = class extends PDFObjectParser {
|
|
7511
|
-
constructor(pdfBytes, objectsPerTick = Infinity, throwOnInvalidObject = false, capNumbers = false, cryptoFactory) {
|
|
7594
|
+
constructor(pdfBytes, objectsPerTick = Infinity, throwOnInvalidObject = false, capNumbers = false, cryptoFactory, encryptRef) {
|
|
7512
7595
|
super(ByteStream.of(pdfBytes), PDFContext.create(), capNumbers, cryptoFactory);
|
|
7513
7596
|
_defineProperty(this, "objectsPerTick", void 0);
|
|
7514
7597
|
_defineProperty(this, "throwOnInvalidObject", void 0);
|
|
7598
|
+
_defineProperty(this, "encryptRef", void 0);
|
|
7515
7599
|
_defineProperty(this, "alreadyParsed", false);
|
|
7516
7600
|
_defineProperty(this, "parsedObjects", 0);
|
|
7517
7601
|
_defineProperty(this, "shouldWaitForTick", () => {
|
|
@@ -7520,6 +7604,7 @@ var PDFParser = class extends PDFObjectParser {
|
|
|
7520
7604
|
});
|
|
7521
7605
|
this.objectsPerTick = objectsPerTick;
|
|
7522
7606
|
this.throwOnInvalidObject = throwOnInvalidObject;
|
|
7607
|
+
this.encryptRef = encryptRef;
|
|
7523
7608
|
this.context.isDecrypted = !!cryptoFactory?.encryptionKey;
|
|
7524
7609
|
}
|
|
7525
7610
|
async parseDocument() {
|
|
@@ -7586,7 +7671,7 @@ var PDFParser = class extends PDFObjectParser {
|
|
|
7586
7671
|
async parseIndirectObject() {
|
|
7587
7672
|
const ref = this.parseIndirectObjectHeader();
|
|
7588
7673
|
this.skipWhitespaceAndComments();
|
|
7589
|
-
const object = this.parseObject(ref);
|
|
7674
|
+
const object = this.parseObject(ref === this.encryptRef ? void 0 : ref);
|
|
7590
7675
|
this.skipWhitespaceAndComments();
|
|
7591
7676
|
this.matchKeyword(Keywords.endobj);
|
|
7592
7677
|
if (object instanceof PDFRawStream && object.dict.lookup(PDFName.of("Type")) === PDFName.of("ObjStm")) await PDFObjectStreamParser.forStream(object, this.shouldWaitForTick).parseIntoContext();
|
|
@@ -7730,7 +7815,7 @@ var PDFParser = class extends PDFObjectParser {
|
|
|
7730
7815
|
}
|
|
7731
7816
|
};
|
|
7732
7817
|
_PDFParser = PDFParser;
|
|
7733
|
-
_defineProperty(PDFParser, "forBytesWithOptions", (pdfBytes, objectsPerTick, throwOnInvalidObject, capNumbers, cryptoFactory) => new _PDFParser(pdfBytes, objectsPerTick, throwOnInvalidObject, capNumbers, cryptoFactory));
|
|
7818
|
+
_defineProperty(PDFParser, "forBytesWithOptions", (pdfBytes, objectsPerTick, throwOnInvalidObject, capNumbers, cryptoFactory, encryptRef) => new _PDFParser(pdfBytes, objectsPerTick, throwOnInvalidObject, capNumbers, cryptoFactory, encryptRef));
|
|
7734
7819
|
//#endregion
|
|
7735
7820
|
//#region src/core/annotation/flags.ts
|
|
7736
7821
|
var flag = (bitIndex) => 1 << bitIndex;
|
|
@@ -15600,12 +15685,6 @@ var CipherTransform = class {
|
|
|
15600
15685
|
return cipher.decryptBlock(data, finalize);
|
|
15601
15686
|
}, length);
|
|
15602
15687
|
}
|
|
15603
|
-
decryptString(s) {
|
|
15604
|
-
const cipher = this.StringCipherConstructor();
|
|
15605
|
-
let data = stringAsByteArray(s);
|
|
15606
|
-
data = cipher.decryptBlock(data, true);
|
|
15607
|
-
return arrayAsString(data);
|
|
15608
|
-
}
|
|
15609
15688
|
decryptBytes(d) {
|
|
15610
15689
|
return this.StringCipherConstructor().decryptBlock(d, true);
|
|
15611
15690
|
}
|
|
@@ -15943,7 +16022,7 @@ var PDFDocument = class PDFDocument {
|
|
|
15943
16022
|
if (!!context.lookup(context.trailerInfo.Encrypt) && password !== void 0) {
|
|
15944
16023
|
const fileIds = context.lookup(context.trailerInfo.ID, PDFArray);
|
|
15945
16024
|
const encryptDict = context.lookup(context.trailerInfo.Encrypt, PDFDict);
|
|
15946
|
-
const decryptedContext = await PDFParser.forBytesWithOptions(bytes, parseSpeed, throwOnInvalidObject, capNumbers, new CipherTransformFactory(encryptDict, fileIds.get(0).asBytes(), password)).parseDocument();
|
|
16025
|
+
const decryptedContext = await PDFParser.forBytesWithOptions(bytes, parseSpeed, throwOnInvalidObject, capNumbers, new CipherTransformFactory(encryptDict, fileIds.get(0).asBytes(), password), context.trailerInfo.Encrypt instanceof PDFRef ? context.trailerInfo.Encrypt : void 0).parseDocument();
|
|
15947
16026
|
return new PDFDocument(decryptedContext, true, updateMetadata);
|
|
15948
16027
|
} else return new PDFDocument(context, ignoreEncryption, updateMetadata);
|
|
15949
16028
|
}
|
|
@@ -16289,7 +16368,7 @@ var PDFDocument = class PDFDocument {
|
|
|
16289
16368
|
setLanguage(language) {
|
|
16290
16369
|
assertIs(language, "language", ["string"]);
|
|
16291
16370
|
const key = PDFName.of("Lang");
|
|
16292
|
-
this.catalog.set(key, PDFString.
|
|
16371
|
+
this.catalog.set(key, PDFString.fromBytes(stringAsByteArray(language)));
|
|
16293
16372
|
}
|
|
16294
16373
|
/**
|
|
16295
16374
|
* Set this document's creation date metadata. The creation date will appear
|
|
@@ -19250,6 +19329,6 @@ var PDFButton = class extends PDFField {
|
|
|
19250
19329
|
_PDFButton = PDFButton;
|
|
19251
19330
|
_defineProperty(PDFButton, "of", (acroPushButton, ref, doc) => new _PDFButton(acroPushButton, ref, doc));
|
|
19252
19331
|
//#endregion
|
|
19253
|
-
export { AFRelationship, AcroButtonFlags, AcroChoiceFlags, AcroFieldFlags, AcroTextFlags, AnnotationFlags, AppearanceCharacteristics, BlendMode, Cache, CharCodes, ColorTypes, CombedTextLayoutError, CorruptPageTreeError, CustomFontEmbedder, CustomFontSubsetEmbedder, DecompressionBombError, Duplex, EncryptedPDFError, ExceededMaxLengthError, FieldAlreadyExistsError, FieldExistsAsNonTerminalError, FileEmbedder, FillRule, FontkitNotRegisteredError, ForeignPageError, ImageAlignment, IndexOutOfBoundsError, InvalidAcroFieldValueError, InvalidFieldNamePartError, InvalidMaxLengthError, InvalidPDFDateStringError, InvalidTargetIndexError, JpegEmbedder, LineCapStyle, LineJoinStyle, MethodNotImplementedError, MissingCatalogError, MissingDAEntryError, MissingKeywordError, MissingOnValueCheckError, MissingPDFHeaderError, MissingPageContentsEmbeddingError, MissingTfOperatorError, MultiSelectValueError, NextByteAssertionError, NoSuchFieldError, NonFullScreenPageMode, NumberParsingError, PDFAcroButton, PDFAcroCheckBox, PDFAcroChoice, PDFAcroComboBox, PDFAcroField, PDFAcroForm, PDFAcroListBox, PDFAcroNonTerminal, PDFAcroPushButton, PDFAcroRadioButton, PDFAcroSignature, PDFAcroTerminal, PDFAcroText, PDFAnnotation, PDFArray, PDFArrayIsNotRectangleError, PDFBool, PDFButton, PDFCatalog, PDFCheckBox, PDFContentStream, PDFContext, PDFCrossRefSection, PDFCrossRefStream, PDFDict, PDFDocument, PDFDropdown, PDFEmbeddedPage, PDFField, PDFFlateStream, PDFFont, PDFForm, PDFHeader, PDFHexString, PDFImage, PDFInvalidObject, PDFInvalidObjectParsingError, PDFJavaScript, PDFName, PDFNull_default as PDFNull, PDFNumber, PDFObject, PDFObjectCopier, PDFObjectParser, PDFObjectParsingError, PDFObjectStream, PDFObjectStreamParser, PDFOperator, PDFOperatorNames, PDFOptionList, PDFPage, PDFPageEmbedder, PDFPageLeaf, PDFPageTree, PDFParser, PDFParsingError, PDFRadioGroup, PDFRawStream, PDFRef, PDFSignature, PDFStream, PDFStreamParsingError, PDFStreamWriter, PDFString, PDFTextField, PDFTrailer, PDFTrailerDict, PDFWidgetAnnotation, PDFWriter, PDFXRefStreamParser, PageEmbeddingMismatchedContextError, PageSizes, ParseSpeeds, PngEmbedder, PrintScaling, PrivateConstructorError, ReadingDirection, RemovePageFromEmptyDocumentError, ReparseError, RichTextFieldReadError, RotationTypes, StalledParserError, StandardFontEmbedder, StandardFontValues, StandardFonts, TextAlignment, TextRenderingMode, UnbalancedParenthesisError, UnexpectedFieldTypeError, UnexpectedObjectTypeError, UnrecognizedStreamTypeError, UnsupportedEncodingError, ViewerPreferences, addRandomSuffix, adjustDimsForRotation, appendBezierCurve, appendQuadraticCurve, arrayAsString, asNumber, asPDFName, asPDFNumber, assertEachIs, assertInteger, assertIs, assertIsOneOf, assertIsOneOfOrUndefined, assertIsSubset, assertMultiple, assertOrUndefined, assertPositive, assertRange, assertRangeOrUndefined, backtick, beginMarkedContent, beginText, breakTextIntoLines, byAscendingId, bytesFor, canBeConvertedToUint8Array, charAtIndex, charFromCode, charFromHexCode, charSplit, cleanText, clip, clipEvenOdd, closePath, cmyk, colorString, colorToComponents, componentsToColor, concatTransformationMatrix, copyStringIntoBuffer, createPDFAcroField, createPDFAcroFields, createTypeErrorMsg, createValueErrorMsg, decodeFromBase64, decodeFromBase64DataUri, decodePDFRawStream, defaultButtonAppearanceProvider, defaultCheckBoxAppearanceProvider, defaultDropdownAppearanceProvider, defaultOptionListAppearanceProvider, defaultRadioGroupAppearanceProvider, defaultTextFieldAppearanceProvider, degrees, degreesToRadians, drawButton, drawCheckBox, drawCheckMark, drawEllipse, drawEllipsePath, drawImage, drawLine, drawLinesOfText, drawObject, drawOptionList, drawPage, drawRadioButton, drawRectangle, drawSvgPath, drawText, drawTextField, drawTextLines, encodeToBase64, endMarkedContent, endPath, endText, error, escapeRegExp, escapedNewlineChars, fill, fillAndStroke, fillEvenOdd, findLastMatch, getType, grayscale, hasSurrogates, hasUtf16BOM, highSurrogate, isArrayEqual, isNewlineChar, isStandardFont, isType, isWithinBMP, last, layoutCombedText, layoutMultilineText, layoutSinglelineText, lineSplit, lineTo, lowSurrogate, mergeIntoTypedArray, mergeLines, mergeUint8Arrays, moveText, moveTo, newlineChars, nextLine, normalizeAppearance, numberToString, padStart, parseDate, pdfDocEncodingDecode, pluckIndices, popGraphicsState, pushGraphicsState, radians, radiansToDegrees, range, rectangle, rectanglesAreEqual, reduceRotation, restoreDashPattern, reverseArray, rgb, rotateAndSkewTextDegreesAndTranslate, rotateAndSkewTextRadiansAndTranslate, rotateDegrees, rotateInPlace, rotateRadians, rotateRectangle, scale, setCharacterSpacing, setCharacterSqueeze, setDashPattern, setFillingCmykColor, setFillingColor, setFillingGrayscaleColor, setFillingRgbColor, setFontAndSize, setGraphicsState, setLineCap, setLineHeight, setLineJoin, setLineWidth, setStrokingCmykColor, setStrokingColor, setStrokingGrayscaleColor, setStrokingRgbColor, setTextMatrix, setTextRenderingMode, setTextRise, setWordSpacing, showText, singleQuote, sizeInBytes, skewDegrees, skewRadians, sortedUniq, splitTextIntoShapingRuns, square, stringAsByteArray, stroke, sum, toCharCode, toCodePoint, toDegrees, toHexString, toHexStringOfMinLength, toRadians, toUint8Array, translate, typedArrayFor, utf16Decode, utf16Encode, utf8Encode, values, waitForTick };
|
|
19332
|
+
export { AFRelationship, AcroButtonFlags, AcroChoiceFlags, AcroFieldFlags, AcroTextFlags, AnnotationFlags, AppearanceCharacteristics, BlendMode, Cache, CharCodes, ColorTypes, CombedTextLayoutError, CorruptPageTreeError, CustomFontEmbedder, CustomFontSubsetEmbedder, DecompressionBombError, Duplex, EncryptedPDFError, ExceededMaxLengthError, FieldAlreadyExistsError, FieldExistsAsNonTerminalError, FileEmbedder, FillRule, FontkitNotRegisteredError, ForeignPageError, ImageAlignment, IndexOutOfBoundsError, InvalidAcroFieldValueError, InvalidFieldNamePartError, InvalidMaxLengthError, InvalidPDFDateStringError, InvalidTargetIndexError, JpegEmbedder, LineCapStyle, LineJoinStyle, MethodNotImplementedError, MissingCatalogError, MissingDAEntryError, MissingKeywordError, MissingOnValueCheckError, MissingPDFHeaderError, MissingPageContentsEmbeddingError, MissingTfOperatorError, MultiSelectValueError, NextByteAssertionError, NoSuchFieldError, NonFullScreenPageMode, NumberParsingError, PDFAcroButton, PDFAcroCheckBox, PDFAcroChoice, PDFAcroComboBox, PDFAcroField, PDFAcroForm, PDFAcroListBox, PDFAcroNonTerminal, PDFAcroPushButton, PDFAcroRadioButton, PDFAcroSignature, PDFAcroTerminal, PDFAcroText, PDFAnnotation, PDFArray, PDFArrayIsNotRectangleError, PDFBool, PDFButton, PDFCatalog, PDFCheckBox, PDFContentStream, PDFContext, PDFCrossRefSection, PDFCrossRefStream, PDFDict, PDFDocument, PDFDropdown, PDFEmbeddedPage, PDFField, PDFFlateStream, PDFFont, PDFForm, PDFHeader, PDFHexString, PDFImage, PDFInvalidObject, PDFInvalidObjectParsingError, PDFJavaScript, PDFName, PDFNull_default as PDFNull, PDFNumber, PDFObject, PDFObjectCopier, PDFObjectParser, PDFObjectParsingError, PDFObjectStream, PDFObjectStreamParser, PDFOperator, PDFOperatorNames, PDFOptionList, PDFPage, PDFPageEmbedder, PDFPageLeaf, PDFPageTree, PDFParser, PDFParsingError, PDFRadioGroup, PDFRawStream, PDFRef, PDFSignature, PDFStream, PDFStreamParsingError, PDFStreamWriter, PDFString, PDFTextField, PDFTrailer, PDFTrailerDict, PDFWidgetAnnotation, PDFWriter, PDFXRefStreamParser, PageEmbeddingMismatchedContextError, PageSizes, ParseSpeeds, PngEmbedder, PrintScaling, PrivateConstructorError, ReadingDirection, RemovePageFromEmptyDocumentError, ReparseError, RichTextFieldReadError, RotationTypes, StalledParserError, StandardFontEmbedder, StandardFontValues, StandardFonts, TextAlignment, TextRenderingMode, UnbalancedParenthesisError, UnexpectedFieldTypeError, UnexpectedObjectTypeError, UnrecognizedStreamTypeError, UnsupportedEncodingError, ViewerPreferences, addRandomSuffix, adjustDimsForRotation, appendBezierCurve, appendQuadraticCurve, arrayAsString, asNumber, asPDFName, asPDFNumber, assertEachIs, assertInteger, assertIs, assertIsOneOf, assertIsOneOfOrUndefined, assertIsSubset, assertMultiple, assertOrUndefined, assertPositive, assertRange, assertRangeOrUndefined, backtick, beginMarkedContent, beginText, breakTextIntoLines, byAscendingId, bytesFor, canBeConvertedToUint8Array, charAtIndex, charFromCode, charFromHexCode, charSplit, cleanText, clip, clipEvenOdd, closePath, cmyk, colorString, colorToComponents, componentsToColor, concatTransformationMatrix, copyStringIntoBuffer, createPDFAcroField, createPDFAcroFields, createTypeErrorMsg, createValueErrorMsg, decodeFromBase64, decodeFromBase64DataUri, decodePDFRawStream, defaultButtonAppearanceProvider, defaultCheckBoxAppearanceProvider, defaultDropdownAppearanceProvider, defaultOptionListAppearanceProvider, defaultRadioGroupAppearanceProvider, defaultTextFieldAppearanceProvider, degrees, degreesToRadians, drawButton, drawCheckBox, drawCheckMark, drawEllipse, drawEllipsePath, drawImage, drawLine, drawLinesOfText, drawObject, drawOptionList, drawPage, drawRadioButton, drawRectangle, drawSvgPath, drawText, drawTextField, drawTextLines, encodeToBase64, endMarkedContent, endPath, endText, error, escapeRegExp, escapedNewlineChars, fill, fillAndStroke, fillEvenOdd, findLastMatch, getType, grayscale, hasSurrogates, hasUtf16BOM, highSurrogate, isArrayEqual, isNewlineChar, isStandardFont, isType, isWithinBMP, last, layoutCombedText, layoutMultilineText, layoutSinglelineText, lineSplit, lineTo, lowSurrogate, mergeIntoTypedArray, mergeLines, mergeUint8Arrays, moveText, moveTo, newlineChars, nextLine, normalizeAppearance, numberToString, padStart, parseDate, parseFont, pdfDocEncodingDecode, pluckIndices, popGraphicsState, pushGraphicsState, radians, radiansToDegrees, range, rectangle, rectanglesAreEqual, reduceRotation, restoreDashPattern, reverseArray, rgb, rotateAndSkewTextDegreesAndTranslate, rotateAndSkewTextRadiansAndTranslate, rotateDegrees, rotateInPlace, rotateRadians, rotateRectangle, scale, setCharacterSpacing, setCharacterSqueeze, setDashPattern, setFillingCmykColor, setFillingColor, setFillingGrayscaleColor, setFillingRgbColor, setFontAndSize, setGraphicsState, setLineCap, setLineHeight, setLineJoin, setLineWidth, setStrokingCmykColor, setStrokingColor, setStrokingGrayscaleColor, setStrokingRgbColor, setTextMatrix, setTextRenderingMode, setTextRise, setWordSpacing, showText, singleQuote, sizeInBytes, skewDegrees, skewRadians, sortedUniq, splitTextIntoShapingRuns, square, stringAsByteArray, stroke, sum, toCharCode, toCodePoint, toDegrees, toHexString, toHexStringOfMinLength, toRadians, toUint8Array, translate, typedArrayFor, utf16Decode, utf16Encode, utf8Encode, values, waitForTick };
|
|
19254
19333
|
|
|
19255
19334
|
//# sourceMappingURL=index.js.map
|