@libpdf/core 0.0.1-beta.7 → 0.0.1-beta.9
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/index.d.mts +59 -33
- package/dist/index.mjs +75 -116
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
import * as _google_cloud_kms0 from "@google-cloud/kms";
|
|
3
2
|
import * as _google_cloud_secret_manager0 from "@google-cloud/secret-manager";
|
|
4
3
|
|
|
@@ -1931,6 +1930,12 @@ interface Permissions {
|
|
|
1931
1930
|
}
|
|
1932
1931
|
//#endregion
|
|
1933
1932
|
//#region src/security/schemas.d.ts
|
|
1933
|
+
/**
|
|
1934
|
+
* Zod schemas for PDF encryption dictionary validation.
|
|
1935
|
+
*
|
|
1936
|
+
* These schemas provide type-safe parsing of encryption parameters
|
|
1937
|
+
* with proper validation and TypeScript type inference.
|
|
1938
|
+
*/
|
|
1934
1939
|
/**
|
|
1935
1940
|
* Valid encryption versions (V entry).
|
|
1936
1941
|
*
|
|
@@ -1940,8 +1945,7 @@ interface Permissions {
|
|
|
1940
1945
|
* - 4: AES-128 or RC4 with crypt filters (PDF 1.5)
|
|
1941
1946
|
* - 5: AES-256 (PDF 2.0)
|
|
1942
1947
|
*/
|
|
1943
|
-
|
|
1944
|
-
type Version = z.infer<typeof VersionSchema>;
|
|
1948
|
+
type EncryptionVersion = 1 | 2 | 3 | 4 | 5;
|
|
1945
1949
|
/**
|
|
1946
1950
|
* Valid encryption revisions (R entry).
|
|
1947
1951
|
*
|
|
@@ -1951,25 +1955,31 @@ type Version = z.infer<typeof VersionSchema>;
|
|
|
1951
1955
|
* - 5: V=5, AES-256 (draft, Adobe Extension Level 3)
|
|
1952
1956
|
* - 6: V=5, AES-256 (final, ISO 32000-2)
|
|
1953
1957
|
*/
|
|
1954
|
-
|
|
1955
|
-
|
|
1958
|
+
type EncryptionRevision = 2 | 3 | 4 | 5 | 6;
|
|
1959
|
+
/**
|
|
1960
|
+
* Crypt filter methods (CFM entry).
|
|
1961
|
+
*
|
|
1962
|
+
* - None: Identity (no encryption)
|
|
1963
|
+
* - V2: RC4
|
|
1964
|
+
* - AESV2: AES-128
|
|
1965
|
+
* - AESV3: AES-256
|
|
1966
|
+
*/
|
|
1967
|
+
type CryptFilterMethod = "None" | "V2" | "AESV2" | "AESV3";
|
|
1968
|
+
/**
|
|
1969
|
+
* Authentication events (AuthEvent entry).
|
|
1970
|
+
*
|
|
1971
|
+
* - DocOpen: Authentication when document is opened
|
|
1972
|
+
* - EFOpen: Authentication when embedded file is accessed
|
|
1973
|
+
*/
|
|
1974
|
+
type AuthEvent = "DocOpen" | "EFOpen";
|
|
1956
1975
|
/**
|
|
1957
1976
|
* Complete crypt filter configuration.
|
|
1958
1977
|
*/
|
|
1959
|
-
|
|
1960
|
-
cfm:
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
AESV3: "AESV3";
|
|
1965
|
-
}>;
|
|
1966
|
-
authEvent: z.ZodOptional<z.ZodEnum<{
|
|
1967
|
-
DocOpen: "DocOpen";
|
|
1968
|
-
EFOpen: "EFOpen";
|
|
1969
|
-
}>>;
|
|
1970
|
-
length: z.ZodOptional<z.ZodNumber>;
|
|
1971
|
-
}, z.core.$strip>;
|
|
1972
|
-
type CryptFilter = z.infer<typeof CryptFilterSchema>;
|
|
1978
|
+
interface CryptFilter {
|
|
1979
|
+
cfm: CryptFilterMethod;
|
|
1980
|
+
authEvent?: AuthEvent;
|
|
1981
|
+
length?: number;
|
|
1982
|
+
}
|
|
1973
1983
|
/**
|
|
1974
1984
|
* Supported encryption algorithms.
|
|
1975
1985
|
*
|
|
@@ -1977,12 +1987,7 @@ type CryptFilter = z.infer<typeof CryptFilterSchema>;
|
|
|
1977
1987
|
* - AES-128: AES with 128-bit key (R4)
|
|
1978
1988
|
* - AES-256: AES with 256-bit key (R5-R6)
|
|
1979
1989
|
*/
|
|
1980
|
-
|
|
1981
|
-
RC4: "RC4";
|
|
1982
|
-
"AES-128": "AES-128";
|
|
1983
|
-
"AES-256": "AES-256";
|
|
1984
|
-
}>;
|
|
1985
|
-
type EncryptionAlgorithm = z.infer<typeof EncryptionAlgorithmSchema>;
|
|
1990
|
+
type EncryptionAlgorithm = "RC4" | "AES-128" | "AES-256";
|
|
1986
1991
|
//#endregion
|
|
1987
1992
|
//#region src/security/errors.d.ts
|
|
1988
1993
|
/**
|
|
@@ -2021,9 +2026,9 @@ interface EncryptionDict {
|
|
|
2021
2026
|
/** Security handler filter (always "Standard" for this implementation) */
|
|
2022
2027
|
filter: "Standard";
|
|
2023
2028
|
/** Algorithm version: 1, 2, 3, 4, or 5 */
|
|
2024
|
-
version:
|
|
2029
|
+
version: EncryptionVersion;
|
|
2025
2030
|
/** Standard security handler revision: 2, 3, 4, 5, or 6 */
|
|
2026
|
-
revision:
|
|
2031
|
+
revision: EncryptionRevision;
|
|
2027
2032
|
/** Key length in bits (40-256) */
|
|
2028
2033
|
keyLengthBits: number;
|
|
2029
2034
|
/** Owner password verification value (32 bytes for R2-R4, 48 bytes for R5-R6) */
|
|
@@ -2120,11 +2125,11 @@ declare class StandardSecurityHandler {
|
|
|
2120
2125
|
/**
|
|
2121
2126
|
* Get the encryption version.
|
|
2122
2127
|
*/
|
|
2123
|
-
get version():
|
|
2128
|
+
get version(): EncryptionVersion;
|
|
2124
2129
|
/**
|
|
2125
2130
|
* Get the encryption revision.
|
|
2126
2131
|
*/
|
|
2127
|
-
get revision():
|
|
2132
|
+
get revision(): EncryptionRevision;
|
|
2128
2133
|
/**
|
|
2129
2134
|
* Get document permissions.
|
|
2130
2135
|
*/
|
|
@@ -2339,18 +2344,22 @@ interface Signer {
|
|
|
2339
2344
|
/** Signature algorithm - required for CMS construction */
|
|
2340
2345
|
readonly signatureAlgorithm: SignatureAlgorithm;
|
|
2341
2346
|
/**
|
|
2342
|
-
* Sign data and return
|
|
2347
|
+
* Sign data and return signature bytes.
|
|
2343
2348
|
*
|
|
2344
2349
|
* The signer is responsible for hashing the data using the specified algorithm
|
|
2345
2350
|
* before creating the signature. For WebCrypto-based implementations, this is
|
|
2346
2351
|
* handled automatically by the sign() function.
|
|
2347
2352
|
*
|
|
2348
|
-
*
|
|
2349
|
-
*
|
|
2353
|
+
* Signature format requirements:
|
|
2354
|
+
* - RSA: PKCS#1 v1.5 or PSS signature bytes
|
|
2355
|
+
* - ECDSA: DER-encoded SEQUENCE { INTEGER r, INTEGER s }
|
|
2356
|
+
*
|
|
2357
|
+
* Note: WebCrypto returns ECDSA signatures in P1363 format (r || s concatenated).
|
|
2358
|
+
* Use pkijs.createCMSECDSASignature() to convert to DER format.
|
|
2350
2359
|
*
|
|
2351
2360
|
* @param data - The data to sign (will be hashed internally)
|
|
2352
2361
|
* @param algorithm - The digest algorithm to use for hashing
|
|
2353
|
-
* @returns
|
|
2362
|
+
* @returns Signature bytes in the format required by CMS/PKCS#7
|
|
2354
2363
|
*/
|
|
2355
2364
|
sign(data: Uint8Array, algorithm: DigestAlgorithm): Promise<Uint8Array>;
|
|
2356
2365
|
}
|
|
@@ -6492,6 +6501,16 @@ interface FlattenOptions {
|
|
|
6492
6501
|
font?: FormFont;
|
|
6493
6502
|
/** Font size to use (0 = auto) */
|
|
6494
6503
|
fontSize?: number;
|
|
6504
|
+
/**
|
|
6505
|
+
* Skip signature fields during flattening.
|
|
6506
|
+
*
|
|
6507
|
+
* When true, signature fields are preserved as interactive fields while
|
|
6508
|
+
* all other fields are flattened. This is useful when you want to flatten
|
|
6509
|
+
* filled form data but keep signature fields available for signing.
|
|
6510
|
+
*
|
|
6511
|
+
* @default false
|
|
6512
|
+
*/
|
|
6513
|
+
skipSignatures?: boolean;
|
|
6495
6514
|
}
|
|
6496
6515
|
//#endregion
|
|
6497
6516
|
//#region src/document/forms/acro-form.d.ts
|
|
@@ -7245,6 +7264,13 @@ declare class PDFForm {
|
|
|
7245
7264
|
* await pdf.form.flatten();
|
|
7246
7265
|
* const bytes = await pdf.save();
|
|
7247
7266
|
* ```
|
|
7267
|
+
*
|
|
7268
|
+
* @example Flatten while preserving signature fields
|
|
7269
|
+
* ```typescript
|
|
7270
|
+
* await pdf.form.fill({ name: "John Doe" });
|
|
7271
|
+
* await pdf.form.flatten({ skipSignatures: true });
|
|
7272
|
+
* // Signature fields remain interactive for signing
|
|
7273
|
+
* ```
|
|
7248
7274
|
*/
|
|
7249
7275
|
flatten(options?: FlattenOptions): void;
|
|
7250
7276
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import pako, { deflate, inflate } from "pako";
|
|
2
|
-
import { z } from "zod";
|
|
3
2
|
import { cbc, ecb } from "@noble/ciphers/aes.js";
|
|
4
3
|
import { randomBytes } from "@noble/ciphers/utils.js";
|
|
5
4
|
import { md5, sha1 } from "@noble/hashes/legacy.js";
|
|
6
5
|
import { sha256, sha384, sha512 } from "@noble/hashes/sha2.js";
|
|
7
6
|
import { Boolean, Constructed, Integer, Null, ObjectIdentifier, OctetString, Sequence, UTCTime, fromBER } from "asn1js";
|
|
8
7
|
import * as pkijs from "pkijs";
|
|
8
|
+
import { createCMSECDSASignature } from "pkijs";
|
|
9
9
|
import { base64 } from "@scure/base";
|
|
10
10
|
|
|
11
11
|
//#region package.json
|
|
12
|
-
var version = "0.0.1-beta.
|
|
12
|
+
var version = "0.0.1-beta.9";
|
|
13
13
|
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/objects/pdf-array.ts
|
|
@@ -3923,85 +3923,23 @@ function encodePermissions(permissions) {
|
|
|
3923
3923
|
|
|
3924
3924
|
//#endregion
|
|
3925
3925
|
//#region src/security/schemas.ts
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
z.literal(2),
|
|
3944
|
-
z.literal(3),
|
|
3945
|
-
z.literal(4),
|
|
3946
|
-
z.literal(5)
|
|
3947
|
-
]);
|
|
3948
|
-
/**
|
|
3949
|
-
* Valid encryption revisions (R entry).
|
|
3950
|
-
*
|
|
3951
|
-
* - 2: V=1, 40-bit RC4
|
|
3952
|
-
* - 3: V=2, 40-128 bit RC4
|
|
3953
|
-
* - 4: V=4, AES-128 or RC4
|
|
3954
|
-
* - 5: V=5, AES-256 (draft, Adobe Extension Level 3)
|
|
3955
|
-
* - 6: V=5, AES-256 (final, ISO 32000-2)
|
|
3956
|
-
*/
|
|
3957
|
-
const RevisionSchema = z.union([
|
|
3958
|
-
z.literal(2),
|
|
3959
|
-
z.literal(3),
|
|
3960
|
-
z.literal(4),
|
|
3961
|
-
z.literal(5),
|
|
3962
|
-
z.literal(6)
|
|
3963
|
-
]);
|
|
3964
|
-
/**
|
|
3965
|
-
* Crypt filter methods (CFM entry).
|
|
3966
|
-
*
|
|
3967
|
-
* - None: Identity (no encryption)
|
|
3968
|
-
* - V2: RC4
|
|
3969
|
-
* - AESV2: AES-128
|
|
3970
|
-
* - AESV3: AES-256
|
|
3971
|
-
*/
|
|
3972
|
-
const CryptFilterMethodSchema = z.enum([
|
|
3973
|
-
"None",
|
|
3974
|
-
"V2",
|
|
3975
|
-
"AESV2",
|
|
3976
|
-
"AESV3"
|
|
3977
|
-
]);
|
|
3978
|
-
/**
|
|
3979
|
-
* Authentication events (AuthEvent entry).
|
|
3980
|
-
*
|
|
3981
|
-
* - DocOpen: Authentication when document is opened
|
|
3982
|
-
* - EFOpen: Authentication when embedded file is accessed
|
|
3983
|
-
*/
|
|
3984
|
-
const AuthEventSchema = z.enum(["DocOpen", "EFOpen"]);
|
|
3985
|
-
/**
|
|
3986
|
-
* Complete crypt filter configuration.
|
|
3987
|
-
*/
|
|
3988
|
-
const CryptFilterSchema = z.object({
|
|
3989
|
-
cfm: CryptFilterMethodSchema,
|
|
3990
|
-
authEvent: AuthEventSchema.optional(),
|
|
3991
|
-
length: z.number().optional()
|
|
3992
|
-
});
|
|
3993
|
-
/**
|
|
3994
|
-
* Supported encryption algorithms.
|
|
3995
|
-
*
|
|
3996
|
-
* - RC4: Legacy stream cipher (R2-R4)
|
|
3997
|
-
* - AES-128: AES with 128-bit key (R4)
|
|
3998
|
-
* - AES-256: AES with 256-bit key (R5-R6)
|
|
3999
|
-
*/
|
|
4000
|
-
const EncryptionAlgorithmSchema = z.enum([
|
|
4001
|
-
"RC4",
|
|
4002
|
-
"AES-128",
|
|
4003
|
-
"AES-256"
|
|
4004
|
-
]);
|
|
3926
|
+
const isEncryptionVersion = (version$1) => {
|
|
3927
|
+
return typeof version$1 === "number" && version$1 >= 1 && version$1 <= 5;
|
|
3928
|
+
};
|
|
3929
|
+
const isEncryptionRevision = (revision) => {
|
|
3930
|
+
return typeof revision === "number" && revision >= 2 && revision <= 6;
|
|
3931
|
+
};
|
|
3932
|
+
const isCryptFilterMethod = (method) => {
|
|
3933
|
+
return typeof method === "string" && [
|
|
3934
|
+
"None",
|
|
3935
|
+
"V2",
|
|
3936
|
+
"AESV2",
|
|
3937
|
+
"AESV3"
|
|
3938
|
+
].includes(method);
|
|
3939
|
+
};
|
|
3940
|
+
const isAuthEvent = (event) => {
|
|
3941
|
+
return typeof event === "string" && ["DocOpen", "EFOpen"].includes(event);
|
|
3942
|
+
};
|
|
4005
3943
|
|
|
4006
3944
|
//#endregion
|
|
4007
3945
|
//#region src/security/encryption-dict.ts
|
|
@@ -4014,22 +3952,16 @@ const EncryptionAlgorithmSchema = z.enum([
|
|
|
4014
3952
|
* @see PDF 2.0 Specification, Section 7.6.2 (Standard encryption dictionary)
|
|
4015
3953
|
*/
|
|
4016
3954
|
/**
|
|
4017
|
-
* Parse a crypt filter dictionary
|
|
3955
|
+
* Parse a crypt filter dictionary.
|
|
4018
3956
|
*/
|
|
4019
3957
|
function parseCryptFilter(dict) {
|
|
4020
|
-
const
|
|
4021
|
-
const
|
|
3958
|
+
const cfm = dict.getName("CFM")?.value ?? "None";
|
|
3959
|
+
const authEvent = dict.getName("AuthEvent")?.value;
|
|
4022
3960
|
const length = dict.getNumber("Length")?.value;
|
|
4023
|
-
|
|
4024
|
-
if (!
|
|
4025
|
-
let authEvent;
|
|
4026
|
-
if (authEventRaw !== void 0) {
|
|
4027
|
-
const authEventResult = AuthEventSchema.safeParse(authEventRaw);
|
|
4028
|
-
if (!authEventResult.success) throw new EncryptionDictError(`Invalid auth event: ${authEventRaw}`);
|
|
4029
|
-
authEvent = authEventResult.data;
|
|
4030
|
-
}
|
|
3961
|
+
if (!isCryptFilterMethod(cfm)) throw new EncryptionDictError(`Invalid crypt filter method: ${cfm}`);
|
|
3962
|
+
if (authEvent !== void 0 && !isAuthEvent(authEvent)) throw new EncryptionDictError(`Invalid auth event: ${authEvent}`);
|
|
4031
3963
|
return {
|
|
4032
|
-
cfm
|
|
3964
|
+
cfm,
|
|
4033
3965
|
authEvent,
|
|
4034
3966
|
length
|
|
4035
3967
|
};
|
|
@@ -4055,21 +3987,19 @@ function determineAlgorithm(version$1, revision, cryptFilters, streamFilter) {
|
|
|
4055
3987
|
* Parse and validate the encryption version.
|
|
4056
3988
|
*/
|
|
4057
3989
|
function parseVersion(dict) {
|
|
4058
|
-
const
|
|
4059
|
-
if (
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
return result.data;
|
|
3990
|
+
const version$1 = dict.getNumber("V")?.value;
|
|
3991
|
+
if (version$1 === void 0) throw new EncryptionDictError("Missing /V (version) in encryption dictionary");
|
|
3992
|
+
if (!isEncryptionVersion(version$1)) throw new EncryptionDictError(`Unsupported encryption version: ${version$1}`);
|
|
3993
|
+
return version$1;
|
|
4063
3994
|
}
|
|
4064
3995
|
/**
|
|
4065
3996
|
* Parse and validate the encryption revision.
|
|
4066
3997
|
*/
|
|
4067
3998
|
function parseRevision(dict) {
|
|
4068
|
-
const
|
|
4069
|
-
if (
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
return result.data;
|
|
3999
|
+
const revision = dict.getNumber("R")?.value;
|
|
4000
|
+
if (revision === void 0) throw new EncryptionDictError("Missing /R (revision) in encryption dictionary");
|
|
4001
|
+
if (!isEncryptionRevision(revision)) throw new EncryptionDictError(`Unsupported encryption revision: ${revision}`);
|
|
4002
|
+
return revision;
|
|
4073
4003
|
}
|
|
4074
4004
|
/**
|
|
4075
4005
|
* Parse an encryption dictionary from a PDF dictionary.
|
|
@@ -26236,30 +26166,36 @@ var FormFlattener = class {
|
|
|
26236
26166
|
* Flatten all form fields into static page content.
|
|
26237
26167
|
*/
|
|
26238
26168
|
flatten(options = {}) {
|
|
26239
|
-
|
|
26240
|
-
|
|
26241
|
-
|
|
26242
|
-
|
|
26243
|
-
|
|
26244
|
-
|
|
26245
|
-
|
|
26169
|
+
const allFields = this.form.getFields();
|
|
26170
|
+
const skipSignatures = options.skipSignatures ?? false;
|
|
26171
|
+
const signatureFields = skipSignatures ? allFields.filter((f) => f instanceof SignatureField) : [];
|
|
26172
|
+
const fieldsToFlatten = skipSignatures ? allFields.filter((f) => !(f instanceof SignatureField)) : allFields;
|
|
26173
|
+
if (options.font || options.fontSize !== void 0) for (const field of fieldsToFlatten) {
|
|
26174
|
+
if (field.isReadOnly()) continue;
|
|
26175
|
+
if (options.font) field.setFont(options.font);
|
|
26176
|
+
if (options.fontSize !== void 0) field.setFontSize(options.fontSize);
|
|
26246
26177
|
}
|
|
26247
26178
|
if (!options.skipAppearanceUpdate) this.form.updateAppearances({ forceRegenerate: options.regenerateAppearances });
|
|
26248
|
-
const pageWidgets = this.collectWidgetsByPage();
|
|
26179
|
+
const pageWidgets = this.collectWidgetsByPage(fieldsToFlatten);
|
|
26249
26180
|
for (const { pageRef, widgets } of pageWidgets.values()) this.flattenWidgetsOnPage(pageRef, widgets);
|
|
26250
26181
|
const dict = this.form.getDict();
|
|
26251
|
-
|
|
26182
|
+
if (signatureFields.length > 0) {
|
|
26183
|
+
const sigRefs = signatureFields.map((f) => f.getRef()).filter((ref) => ref !== null);
|
|
26184
|
+
dict.set("Fields", PdfArray.of(...sigRefs));
|
|
26185
|
+
} else dict.set("Fields", new PdfArray([]));
|
|
26252
26186
|
dict.delete("NeedAppearances");
|
|
26253
26187
|
dict.delete("XFA");
|
|
26254
|
-
if (!this.form.hasSignatures) dict.delete("SigFlags");
|
|
26188
|
+
if (!this.form.hasSignatures && signatureFields.length === 0) dict.delete("SigFlags");
|
|
26255
26189
|
}
|
|
26256
26190
|
/**
|
|
26257
26191
|
* Collect all widgets grouped by their containing page.
|
|
26192
|
+
*
|
|
26193
|
+
* @param fields Optional list of fields to collect from. If not provided, uses all form fields.
|
|
26258
26194
|
*/
|
|
26259
|
-
collectWidgetsByPage() {
|
|
26195
|
+
collectWidgetsByPage(fields) {
|
|
26260
26196
|
const result = /* @__PURE__ */ new Map();
|
|
26261
|
-
const
|
|
26262
|
-
for (const field of
|
|
26197
|
+
const fieldsToProcess = fields ?? this.form.getFields();
|
|
26198
|
+
for (const field of fieldsToProcess) for (const widget of field.getWidgets()) {
|
|
26263
26199
|
let pageRef = widget.pageRef;
|
|
26264
26200
|
if (!pageRef) pageRef = this.findPageForWidget(widget);
|
|
26265
26201
|
if (!pageRef) {
|
|
@@ -27838,9 +27774,22 @@ var PDFForm = class PDFForm {
|
|
|
27838
27774
|
* await pdf.form.flatten();
|
|
27839
27775
|
* const bytes = await pdf.save();
|
|
27840
27776
|
* ```
|
|
27777
|
+
*
|
|
27778
|
+
* @example Flatten while preserving signature fields
|
|
27779
|
+
* ```typescript
|
|
27780
|
+
* await pdf.form.fill({ name: "John Doe" });
|
|
27781
|
+
* await pdf.form.flatten({ skipSignatures: true });
|
|
27782
|
+
* // Signature fields remain interactive for signing
|
|
27783
|
+
* ```
|
|
27841
27784
|
*/
|
|
27842
27785
|
flatten(options = {}) {
|
|
27843
27786
|
this._acroForm.flatten(options);
|
|
27787
|
+
if (options.skipSignatures) {
|
|
27788
|
+
const sigFields = this.allFields.filter((f) => f instanceof SignatureField);
|
|
27789
|
+
this.allFields = sigFields;
|
|
27790
|
+
this.fieldsByName = new Map(sigFields.map((f) => [f.name, f]));
|
|
27791
|
+
return;
|
|
27792
|
+
}
|
|
27844
27793
|
this._ctx.catalog.removeAcroForm();
|
|
27845
27794
|
this.allFields = [];
|
|
27846
27795
|
this.fieldsByName.clear();
|
|
@@ -38293,6 +38242,14 @@ var PDF = class PDF {
|
|
|
38293
38242
|
securityHandler = handler;
|
|
38294
38243
|
}
|
|
38295
38244
|
}
|
|
38245
|
+
if (useIncremental && !fileId) {
|
|
38246
|
+
const idArray = this.ctx.info.trailer.getArray("ID");
|
|
38247
|
+
if (idArray && idArray.length >= 2) {
|
|
38248
|
+
const id1 = idArray.at(0);
|
|
38249
|
+
const id2 = idArray.at(1);
|
|
38250
|
+
if (id1 instanceof PdfString && id2 instanceof PdfString) fileId = [id1.bytes, id2.bytes];
|
|
38251
|
+
}
|
|
38252
|
+
}
|
|
38296
38253
|
const useXRefStream = options.useXRefStream ?? (useIncremental ? this.usesXRefStreams : false);
|
|
38297
38254
|
if (useIncremental) {
|
|
38298
38255
|
const result$1 = writeIncremental(this.ctx.registry, {
|
|
@@ -38448,6 +38405,7 @@ var CryptoKeySigner = class {
|
|
|
38448
38405
|
break;
|
|
38449
38406
|
}
|
|
38450
38407
|
const signature = await cryptoEngine$1.sign(signAlgorithm, this.privateKey, new Uint8Array(data));
|
|
38408
|
+
if (this.signatureAlgorithm === "ECDSA") return new Uint8Array(createCMSECDSASignature(signature));
|
|
38451
38409
|
return new Uint8Array(signature);
|
|
38452
38410
|
}
|
|
38453
38411
|
/**
|
|
@@ -40829,6 +40787,7 @@ var P12Signer = class P12Signer {
|
|
|
40829
40787
|
break;
|
|
40830
40788
|
}
|
|
40831
40789
|
const signature = await cryptoEngine.sign(signAlgorithm, this.privateKey, new Uint8Array(data));
|
|
40790
|
+
if (this.signatureAlgorithm === "ECDSA") return new Uint8Array(createCMSECDSASignature(signature));
|
|
40832
40791
|
return new Uint8Array(signature);
|
|
40833
40792
|
}
|
|
40834
40793
|
/**
|