modern-pdf-lib 0.29.0 → 0.30.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/README.md +4 -3
- package/dist/browser.cjs +15 -3
- package/dist/browser.d.cts +5 -5
- package/dist/browser.d.mts +5 -5
- package/dist/browser.mjs +4 -4
- package/dist/{compressionAnalysis-InMeGrqw.d.mts → compressionAnalysis-0m5jJG1_.d.mts} +2 -2
- package/dist/{compressionAnalysis-CyBVhRU5.d.cts.map → compressionAnalysis-0m5jJG1_.d.mts.map} +1 -1
- package/dist/{compressionAnalysis-CyBVhRU5.d.cts → compressionAnalysis-CSBcmi0_.d.cts} +2 -2
- package/dist/{compressionAnalysis-InMeGrqw.d.mts.map → compressionAnalysis-CSBcmi0_.d.cts.map} +1 -1
- package/dist/create.cjs +2 -2
- package/dist/create.d.cts +2 -2
- package/dist/create.d.mts +2 -2
- package/dist/create.mjs +2 -2
- package/dist/{fontEmbed-N-VWoZ0F.d.mts → fontEmbed-Bzv89wgp.d.mts} +2 -2
- package/dist/{fontEmbed-DxtdZxUj.d.cts.map → fontEmbed-Bzv89wgp.d.mts.map} +1 -1
- package/dist/{fontEmbed-DxtdZxUj.d.cts → fontEmbed-Dwl1XeEA.d.cts} +2 -2
- package/dist/{fontEmbed-N-VWoZ0F.d.mts.map → fontEmbed-Dwl1XeEA.d.cts.map} +1 -1
- package/dist/{index--7OpQy6B.d.cts → index-BJ4KxqDL.d.cts} +293 -61
- package/dist/index-BJ4KxqDL.d.cts.map +1 -0
- package/dist/{index-Cai7jC6u.d.mts → index-CERay5r2.d.mts} +293 -61
- package/dist/index-CERay5r2.d.mts.map +1 -0
- package/dist/index.cjs +15 -3
- package/dist/index.d.cts +5 -5
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +4 -4
- package/dist/{layout-DiO_3JLh.cjs → layout-BYXpcYtC.cjs} +2 -2
- package/dist/{layout-D035GpU8.mjs → layout-xOcesNCh.mjs} +2 -2
- package/dist/parse.cjs +1 -1
- package/dist/parse.d.cts +2 -2
- package/dist/parse.d.mts +2 -2
- package/dist/parse.mjs +1 -1
- package/dist/{pdfDocument-5Do0LKQh.d.cts → pdfDocument-B-8iPl_j.d.mts} +85 -3
- package/dist/pdfDocument-B-8iPl_j.d.mts.map +1 -0
- package/dist/{pdfDocument-B_0VSUHL.d.mts → pdfDocument-B8tQcZqj.d.cts} +85 -3
- package/dist/pdfDocument-B8tQcZqj.d.cts.map +1 -0
- package/dist/{pdfDocument-BaQlOkYr.cjs → pdfDocument-Bh4ebDqE.cjs} +41 -2
- package/dist/{pdfDocument-B6czyaVI.mjs → pdfDocument-Cgkkk8F8.mjs} +41 -2
- package/dist/{src-DQ63jYIR.cjs → src-Tb7wHOKz.cjs} +548 -6
- package/dist/{src-Ci9ZjqhP.mjs → src-s9zNsZAT.mjs} +477 -7
- package/package.json +1 -1
- package/dist/index--7OpQy6B.d.cts.map +0 -1
- package/dist/index-Cai7jC6u.d.mts.map +0 -1
- package/dist/pdfDocument-5Do0LKQh.d.cts.map +0 -1
- package/dist/pdfDocument-B_0VSUHL.d.mts.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_pdfDocument = require("./pdfDocument-
|
|
1
|
+
const require_pdfDocument = require("./pdfDocument-Bh4ebDqE.cjs");
|
|
2
2
|
const require_pdfObjects = require("./pdfObjects-BcPlSI0a.cjs");
|
|
3
3
|
const require_streamDecode = require("./streamDecode-kQ-REV7v.cjs");
|
|
4
4
|
const require_pdfForm = require("./pdfForm-BVS_do95.cjs");
|
|
@@ -277,7 +277,7 @@ function compressStream(stream, level) {
|
|
|
277
277
|
* @returns The incremental save result.
|
|
278
278
|
*/
|
|
279
279
|
async function saveDocumentIncremental(originalBytes, doc, options) {
|
|
280
|
-
const { buildDocumentStructure } = await Promise.resolve().then(() => require("./pdfDocument-
|
|
280
|
+
const { buildDocumentStructure } = await Promise.resolve().then(() => require("./pdfDocument-Bh4ebDqE.cjs")).then((n) => n.pdfCatalog_exports);
|
|
281
281
|
const registry = doc.getRegistry();
|
|
282
282
|
const structure = buildDocumentStructure(doc.getInternalPages().map((p) => p.finalize()), {
|
|
283
283
|
producer: doc.getProducer(),
|
|
@@ -29946,6 +29946,476 @@ var RenderCache = class {
|
|
|
29946
29946
|
}
|
|
29947
29947
|
};
|
|
29948
29948
|
//#endregion
|
|
29949
|
+
//#region src/compliance/afAttach.ts
|
|
29950
|
+
/**
|
|
29951
|
+
* @module compliance/afAttach
|
|
29952
|
+
*
|
|
29953
|
+
* Attach embedded / associated files to any PDF object.
|
|
29954
|
+
*
|
|
29955
|
+
* The Associated Files mechanism (`/AF`) lets a PDF declare that one or more
|
|
29956
|
+
* embedded files are *associated* with a given object. ISO 32000-2 allows the
|
|
29957
|
+
* `/AF` key on the document catalog (§7.11.4) as well as on individual objects
|
|
29958
|
+
* — page dictionaries, annotation dictionaries, Form/Image XObject stream
|
|
29959
|
+
* dictionaries, and structure elements (§14.13). Because every one of those
|
|
29960
|
+
* targets is a plain {@link PdfDict}, the same helper attaches `/AF` uniformly.
|
|
29961
|
+
*
|
|
29962
|
+
* In addition, a *document-level* associated file must also be reachable
|
|
29963
|
+
* through the catalog's embedded-files name tree
|
|
29964
|
+
* (`/Names` → `/EmbeddedFiles` → `/Names`). {@link createAssociatedFile} (in
|
|
29965
|
+
* `associatedFiles.ts`) intentionally leaves that wiring to the caller;
|
|
29966
|
+
* {@link registerEmbeddedFile} completes it.
|
|
29967
|
+
*
|
|
29968
|
+
* These are pure builders: they mutate the supplied dictionaries in place and
|
|
29969
|
+
* return nothing. Object numbers / serialization remain the writer's concern.
|
|
29970
|
+
*
|
|
29971
|
+
* Reference: ISO 32000-2:2020, §7.11.4 (embedded file streams) and §14.13
|
|
29972
|
+
* (associated files).
|
|
29973
|
+
*/
|
|
29974
|
+
/**
|
|
29975
|
+
* Attach one or more associated files to any PDF object via its `/AF` key.
|
|
29976
|
+
*
|
|
29977
|
+
* Works uniformly for the document catalog, a page dictionary, an annotation
|
|
29978
|
+
* dictionary, a Form/Image XObject stream's dictionary, or a structure-element
|
|
29979
|
+
* dictionary — all of which are plain {@link PdfDict} instances.
|
|
29980
|
+
*
|
|
29981
|
+
* If `target` has no `/AF` yet, a fresh array (built with
|
|
29982
|
+
* {@link buildAfArray}) is set. If `/AF` is already a {@link PdfArray}, the
|
|
29983
|
+
* new refs are appended to it, preserving the existing entries and order. Any
|
|
29984
|
+
* other (malformed) `/AF` value is replaced with a fresh array.
|
|
29985
|
+
*
|
|
29986
|
+
* @param target The object dictionary to attach the files to.
|
|
29987
|
+
* @param fileSpecRefs Indirect references to file-specification dictionaries.
|
|
29988
|
+
*/
|
|
29989
|
+
function attachAssociatedFiles(target, fileSpecRefs) {
|
|
29990
|
+
const existing = target.get("/AF");
|
|
29991
|
+
if (existing instanceof require_pdfObjects.PdfArray) {
|
|
29992
|
+
for (const ref of fileSpecRefs) existing.push(ref);
|
|
29993
|
+
return;
|
|
29994
|
+
}
|
|
29995
|
+
target.set("/AF", buildAfArray([...fileSpecRefs]));
|
|
29996
|
+
}
|
|
29997
|
+
/**
|
|
29998
|
+
* Locate the `/EmbeddedFiles` name-tree `/Names` array on the catalog,
|
|
29999
|
+
* creating the intermediate `/Names` and `/EmbeddedFiles` dictionaries (and
|
|
30000
|
+
* the leaf `/Names` array) if they do not yet exist. Existing dictionaries
|
|
30001
|
+
* are reused in place rather than replaced.
|
|
30002
|
+
*/
|
|
30003
|
+
function ensureEmbeddedFilesNames(catalog) {
|
|
30004
|
+
const namesEntry = catalog.get("/Names");
|
|
30005
|
+
const namesDict = namesEntry instanceof require_pdfObjects.PdfDict ? namesEntry : new require_pdfObjects.PdfDict();
|
|
30006
|
+
if (namesDict !== namesEntry) catalog.set("/Names", namesDict);
|
|
30007
|
+
const efEntry = namesDict.get("/EmbeddedFiles");
|
|
30008
|
+
const efDict = efEntry instanceof require_pdfObjects.PdfDict ? efEntry : new require_pdfObjects.PdfDict();
|
|
30009
|
+
if (efDict !== efEntry) namesDict.set("/EmbeddedFiles", efDict);
|
|
30010
|
+
const leafEntry = efDict.get("/Names");
|
|
30011
|
+
const leaf = leafEntry instanceof require_pdfObjects.PdfArray ? leafEntry : new require_pdfObjects.PdfArray();
|
|
30012
|
+
if (leaf !== leafEntry) efDict.set("/Names", leaf);
|
|
30013
|
+
return leaf;
|
|
30014
|
+
}
|
|
30015
|
+
/**
|
|
30016
|
+
* Insert a `[name, fileSpecRef]` pair into an embedded-files name-tree `/Names`
|
|
30017
|
+
* array, keeping the array sorted by name. The array is a flat sequence of
|
|
30018
|
+
* alternating key/value entries: `[ name0, ref0, name1, ref1, … ]`.
|
|
30019
|
+
*/
|
|
30020
|
+
function insertNamePairSorted(leaf, name, fileSpecRef) {
|
|
30021
|
+
const items = leaf.items;
|
|
30022
|
+
let insertAt = items.length;
|
|
30023
|
+
for (let i = 0; i < items.length; i += 2) {
|
|
30024
|
+
const entry = items[i];
|
|
30025
|
+
if ((entry instanceof require_pdfObjects.PdfString ? entry.value : "") > name) {
|
|
30026
|
+
insertAt = i;
|
|
30027
|
+
break;
|
|
30028
|
+
}
|
|
30029
|
+
}
|
|
30030
|
+
items.splice(insertAt, 0, require_pdfObjects.PdfString.literal(name), fileSpecRef);
|
|
30031
|
+
}
|
|
30032
|
+
/**
|
|
30033
|
+
* Complete {@link createAssociatedFile}'s "caller responsibility" by wiring a
|
|
30034
|
+
* file-specification reference into the document catalog at the *document
|
|
30035
|
+
* level*.
|
|
30036
|
+
*
|
|
30037
|
+
* Two things happen:
|
|
30038
|
+
* 1. The pair `[PdfString.literal(name), fileSpecRef]` is added to the
|
|
30039
|
+
* catalog's `/Names` → `/EmbeddedFiles` → `/Names` array, keeping the
|
|
30040
|
+
* array's name/value pairs sorted by name (as required for a name tree).
|
|
30041
|
+
* The intermediate dictionaries and the leaf array are created on demand
|
|
30042
|
+
* and reused if already present.
|
|
30043
|
+
* 2. `fileSpecRef` is added to the catalog's `/AF` array (via
|
|
30044
|
+
* {@link attachAssociatedFiles}).
|
|
30045
|
+
*
|
|
30046
|
+
* @param catalog The document catalog dictionary.
|
|
30047
|
+
* @param name The name under which the file is registered in the tree.
|
|
30048
|
+
* @param fileSpecRef Indirect reference to the file-specification dictionary.
|
|
30049
|
+
*/
|
|
30050
|
+
function registerEmbeddedFile(catalog, name, fileSpecRef) {
|
|
30051
|
+
insertNamePairSorted(ensureEmbeddedFilesNames(catalog), name, fileSpecRef);
|
|
30052
|
+
attachAssociatedFiles(catalog, [fileSpecRef]);
|
|
30053
|
+
}
|
|
30054
|
+
//#endregion
|
|
30055
|
+
//#region src/compliance/pageOutputIntent.ts
|
|
30056
|
+
/**
|
|
30057
|
+
* @module compliance/pageOutputIntent
|
|
30058
|
+
*
|
|
30059
|
+
* Per-page and per-stream output intents (ISO 32000-2 §14.11.5).
|
|
30060
|
+
*
|
|
30061
|
+
* In addition to the document-level `/OutputIntents` array carried on the
|
|
30062
|
+
* catalog, PDF 2.0 permits an `/OutputIntents` array on individual *page*
|
|
30063
|
+
* dictionaries and on *Form XObject* stream dictionaries. These narrower
|
|
30064
|
+
* intents override the document intent for the colour-managed content of that
|
|
30065
|
+
* page or form, which is essential for documents that mix output conditions
|
|
30066
|
+
* (for example, a PDF/X job whose individual pages target different print
|
|
30067
|
+
* presses).
|
|
30068
|
+
*
|
|
30069
|
+
* This module provides two pure builders:
|
|
30070
|
+
*
|
|
30071
|
+
* - {@link buildPageOutputIntent} constructs a single `/OutputIntent`
|
|
30072
|
+
* dictionary (reusing {@link buildOutputIntent} for the embedded ICC
|
|
30073
|
+
* `/DestOutputProfile`) and registers it as an indirect object.
|
|
30074
|
+
* - {@link attachOutputIntents} sets — or, when one already exists, appends
|
|
30075
|
+
* to — the `/OutputIntents` array on a target dictionary (a page dict for
|
|
30076
|
+
* per-page intents, or a Form XObject stream's dict for per-stream).
|
|
30077
|
+
*
|
|
30078
|
+
* Reference: ISO 32000-2:2020, §14.11.5 (Output intents).
|
|
30079
|
+
*/
|
|
30080
|
+
/**
|
|
30081
|
+
* Attach output-intent references to a target dictionary's `/OutputIntents`
|
|
30082
|
+
* array.
|
|
30083
|
+
*
|
|
30084
|
+
* If the target has no `/OutputIntents` entry, a fresh {@link PdfArray} is
|
|
30085
|
+
* created and populated with `intentRefs`. If one already exists (and is an
|
|
30086
|
+
* array), the references are appended to it in order, preserving the existing
|
|
30087
|
+
* array instance.
|
|
30088
|
+
*
|
|
30089
|
+
* The target may be a page dictionary (for per-page intents) or a Form
|
|
30090
|
+
* XObject stream's dictionary (for per-stream intents).
|
|
30091
|
+
*
|
|
30092
|
+
* @param target The page or Form XObject dictionary to mutate.
|
|
30093
|
+
* @param intentRefs Indirect references to `/OutputIntent` dictionaries.
|
|
30094
|
+
*/
|
|
30095
|
+
function attachOutputIntents(target, intentRefs) {
|
|
30096
|
+
const existing = target.get("/OutputIntents");
|
|
30097
|
+
const array = existing instanceof require_pdfObjects.PdfArray ? existing : new require_pdfObjects.PdfArray();
|
|
30098
|
+
for (const ref of intentRefs) array.push(ref);
|
|
30099
|
+
if (!(existing instanceof require_pdfObjects.PdfArray)) target.set("/OutputIntents", array);
|
|
30100
|
+
}
|
|
30101
|
+
/**
|
|
30102
|
+
* Build a per-page / per-stream `/OutputIntent` dictionary and register it.
|
|
30103
|
+
*
|
|
30104
|
+
* The embedded ICC `/DestOutputProfile` is produced by reusing
|
|
30105
|
+
* {@link buildOutputIntent}; this builder then layers the per-page subtype
|
|
30106
|
+
* (`/S`), output-condition identifier and optional `/Info` string on top.
|
|
30107
|
+
* The resulting dictionary carries `/Type /OutputIntent` and may be attached
|
|
30108
|
+
* to a page or Form XObject dictionary via {@link attachOutputIntents}.
|
|
30109
|
+
*
|
|
30110
|
+
* @param registry The PDF object registry to register objects into.
|
|
30111
|
+
* @param options Output-intent configuration.
|
|
30112
|
+
* @returns An indirect reference to the `/OutputIntent` dictionary.
|
|
30113
|
+
*/
|
|
30114
|
+
function buildPageOutputIntent(registry, options = {}) {
|
|
30115
|
+
const intentRef = buildOutputIntent(registry, {
|
|
30116
|
+
subtype: options.subtype ?? "/GTS_PDFA1",
|
|
30117
|
+
...options.iccProfile !== void 0 ? { iccProfile: options.iccProfile } : {},
|
|
30118
|
+
...options.components !== void 0 ? { components: options.components } : {},
|
|
30119
|
+
...options.outputConditionIdentifier !== void 0 ? { outputConditionIdentifier: options.outputConditionIdentifier } : {}
|
|
30120
|
+
});
|
|
30121
|
+
const intentDict = registry.resolve(intentRef);
|
|
30122
|
+
if (intentDict !== void 0 && intentDict.kind === "dict") {
|
|
30123
|
+
intentDict.set("/Type", require_pdfObjects.PdfName.of("OutputIntent"));
|
|
30124
|
+
if (options.outputConditionIdentifier !== void 0) intentDict.set("/OutputConditionIdentifier", require_pdfObjects.PdfString.literal(options.outputConditionIdentifier));
|
|
30125
|
+
if (options.info !== void 0) intentDict.set("/Info", require_pdfObjects.PdfString.literal(options.info));
|
|
30126
|
+
}
|
|
30127
|
+
return intentRef;
|
|
30128
|
+
}
|
|
30129
|
+
//#endregion
|
|
30130
|
+
//#region src/compliance/encryptedPayload.ts
|
|
30131
|
+
/**
|
|
30132
|
+
* @module compliance/encryptedPayload
|
|
30133
|
+
*
|
|
30134
|
+
* Unencrypted wrapper documents and encrypted payloads
|
|
30135
|
+
* (ISO 32000-2:2020 §7.6.7).
|
|
30136
|
+
*
|
|
30137
|
+
* A PDF 2.0 *unencrypted wrapper document* is an ordinary, viewable PDF that
|
|
30138
|
+
* carries an *encrypted payload* as an embedded file. The wrapper itself is
|
|
30139
|
+
* not encrypted (so any conforming reader can open it and show a cover page),
|
|
30140
|
+
* while the sensitive content lives in the embedded payload, which is
|
|
30141
|
+
* protected by an external/handler-specific crypto filter.
|
|
30142
|
+
*
|
|
30143
|
+
* The payload is declared through an *Encrypted Payload* dictionary
|
|
30144
|
+
* (`/Type /EncryptedPayload`). Its `/Subtype` names the crypto filter used to
|
|
30145
|
+
* protect the payload (for example `/AESV3`), and an optional `/Version`
|
|
30146
|
+
* records the version of that filter. The Encrypted Payload dictionary is
|
|
30147
|
+
* attached to the embedded file's *file specification* dictionary via the
|
|
30148
|
+
* `/EP` key, and that file specification is also marked with
|
|
30149
|
+
* `/AFRelationship /EncryptedPayload`.
|
|
30150
|
+
*
|
|
30151
|
+
* This module provides two pure builders:
|
|
30152
|
+
*
|
|
30153
|
+
* - {@link buildEncryptedPayload} — build the `/EncryptedPayload` dictionary.
|
|
30154
|
+
* - {@link buildUnencryptedWrapper} — embed the payload bytes as an
|
|
30155
|
+
* associated file and attach the `/EP` dictionary to its file
|
|
30156
|
+
* specification, returning the file-spec reference.
|
|
30157
|
+
*
|
|
30158
|
+
* The caller attaches the returned file-spec reference to the catalog `/AF`
|
|
30159
|
+
* array and to the `/Names /EmbeddedFiles` name tree (for example via
|
|
30160
|
+
* `afAttach`).
|
|
30161
|
+
*
|
|
30162
|
+
* Reference: ISO 32000-2:2020, §7.6.7 (Unencrypted wrapper document).
|
|
30163
|
+
*/
|
|
30164
|
+
/**
|
|
30165
|
+
* Build an `/EncryptedPayload` dictionary (ISO 32000-2 §7.6.7).
|
|
30166
|
+
*
|
|
30167
|
+
* The returned dictionary has:
|
|
30168
|
+
* - `/Type /EncryptedPayload`
|
|
30169
|
+
* - `/Subtype /<subtype>` — the crypto filter name
|
|
30170
|
+
* - `/Version /<version>` — only when {@link EncryptedPayloadOptions.version}
|
|
30171
|
+
* is supplied
|
|
30172
|
+
*
|
|
30173
|
+
* @param options - The crypto-filter subtype and optional version.
|
|
30174
|
+
* @returns A spec-shaped `/EncryptedPayload` {@link PdfDict}.
|
|
30175
|
+
*/
|
|
30176
|
+
function buildEncryptedPayload(options) {
|
|
30177
|
+
const dict = new require_pdfObjects.PdfDict();
|
|
30178
|
+
dict.set("/Type", require_pdfObjects.PdfName.of("EncryptedPayload"));
|
|
30179
|
+
dict.set("/Subtype", require_pdfObjects.PdfName.of(options.subtype));
|
|
30180
|
+
if (options.version !== void 0) dict.set("/Version", require_pdfObjects.PdfName.of(options.version));
|
|
30181
|
+
return dict;
|
|
30182
|
+
}
|
|
30183
|
+
/**
|
|
30184
|
+
* Build the embedded encrypted-payload file for an unencrypted wrapper
|
|
30185
|
+
* document and return its file-specification reference.
|
|
30186
|
+
*
|
|
30187
|
+
* The payload bytes are embedded via {@link createAssociatedFile} with an
|
|
30188
|
+
* `/AFRelationship` of `/EncryptedPayload` and an `application/octet-stream`
|
|
30189
|
+
* MIME type. The resolved file-specification dictionary then receives an
|
|
30190
|
+
* `/EP` entry holding the {@link buildEncryptedPayload} dictionary.
|
|
30191
|
+
*
|
|
30192
|
+
* The caller is responsible for attaching the returned file-spec reference to
|
|
30193
|
+
* the catalog `/AF` array and the `/Names /EmbeddedFiles` name tree.
|
|
30194
|
+
*
|
|
30195
|
+
* @param registry - The PDF object registry to register objects into.
|
|
30196
|
+
* @param options - The payload bytes, filename, crypto subtype/version, and
|
|
30197
|
+
* optional description.
|
|
30198
|
+
* @returns An indirect reference to the file-specification dictionary.
|
|
30199
|
+
*/
|
|
30200
|
+
function buildUnencryptedWrapper(registry, options) {
|
|
30201
|
+
const { fileSpecRef } = createAssociatedFile(registry, {
|
|
30202
|
+
data: options.data,
|
|
30203
|
+
filename: options.filename,
|
|
30204
|
+
mimeType: "application/octet-stream",
|
|
30205
|
+
relationship: "EncryptedPayload",
|
|
30206
|
+
description: options.description
|
|
30207
|
+
});
|
|
30208
|
+
const fileSpec = registry.resolve(fileSpecRef);
|
|
30209
|
+
if (fileSpec instanceof require_pdfObjects.PdfDict) {
|
|
30210
|
+
const ep = buildEncryptedPayload({
|
|
30211
|
+
subtype: options.subtype,
|
|
30212
|
+
version: options.version
|
|
30213
|
+
});
|
|
30214
|
+
fileSpec.set("/EP", ep);
|
|
30215
|
+
}
|
|
30216
|
+
return fileSpecRef;
|
|
30217
|
+
}
|
|
30218
|
+
//#endregion
|
|
30219
|
+
//#region src/core/softMask.ts
|
|
30220
|
+
/**
|
|
30221
|
+
* @module core/softMask
|
|
30222
|
+
*
|
|
30223
|
+
* Soft-mask groups in graphics state (ISO 32000-1 §11.6.5.2).
|
|
30224
|
+
*
|
|
30225
|
+
* A *soft mask* defines a per-pixel shape/opacity for subsequent painting
|
|
30226
|
+
* operations. It is carried in an `ExtGState` dictionary under the `/SMask`
|
|
30227
|
+
* key. The mask is derived from a *transparency-group XObject* (a form
|
|
30228
|
+
* XObject whose `/Group` dictionary has `/S /Transparency`):
|
|
30229
|
+
*
|
|
30230
|
+
* - A **luminosity** mask (`/S /Luminosity`) computes the mask value from the
|
|
30231
|
+
* luminosity of the group's composited result. An optional `/BC` backdrop
|
|
30232
|
+
* color sets the colour against which the group is composited before the
|
|
30233
|
+
* luminosity is measured.
|
|
30234
|
+
* - An **alpha** mask (`/S /Alpha`) computes the mask value from the group's
|
|
30235
|
+
* accumulated alpha (shape/opacity). `/BC` is not meaningful and is omitted.
|
|
30236
|
+
*
|
|
30237
|
+
* An optional `/TR` *transfer function* remaps the computed mask values; it may
|
|
30238
|
+
* be an indirect reference to a function object or the name `/Identity`.
|
|
30239
|
+
*
|
|
30240
|
+
* These are pure builders: they return spec-shaped `ExtGState` dictionaries.
|
|
30241
|
+
* Registering the result and naming it in a page's `/Resources /ExtGState`
|
|
30242
|
+
* (e.g. via `page.registerExtGState(name, registry.register(extGState))`) is
|
|
30243
|
+
* the caller's concern.
|
|
30244
|
+
*
|
|
30245
|
+
* Reference: ISO 32000-1:2008, §11.6.5.2 (Mask shape and opacity);
|
|
30246
|
+
* ISO 32000-1:2008, §8.4.5 (Graphics state, `/SMask`).
|
|
30247
|
+
*/
|
|
30248
|
+
/**
|
|
30249
|
+
* Build an `ExtGState` dictionary that installs a soft-mask group.
|
|
30250
|
+
*
|
|
30251
|
+
* The returned dictionary has `/Type /ExtGState` and an `/SMask` mask
|
|
30252
|
+
* dictionary:
|
|
30253
|
+
*
|
|
30254
|
+
* - `/Type /Mask`
|
|
30255
|
+
* - `/S /Luminosity` or `/S /Alpha` (per {@link SoftMaskGroupOptions.type},
|
|
30256
|
+
* defaulting to `Luminosity`)
|
|
30257
|
+
* - `/G` → the supplied group XObject reference
|
|
30258
|
+
* - `/BC [ … ]` — backdrop colour, **only** for luminosity masks and only
|
|
30259
|
+
* when {@link SoftMaskGroupOptions.backdropColor} is provided
|
|
30260
|
+
* - `/TR` → the transfer function (indirect reference) or the name
|
|
30261
|
+
* `/Identity`, only when {@link SoftMaskGroupOptions.transferFunction} is
|
|
30262
|
+
* provided
|
|
30263
|
+
*
|
|
30264
|
+
* @param options - The soft-mask group description.
|
|
30265
|
+
* @returns A spec-shaped `ExtGState` {@link PdfDict}.
|
|
30266
|
+
*/
|
|
30267
|
+
function buildSoftMaskGroupExtGState(options) {
|
|
30268
|
+
const subtype = options.type ?? "Luminosity";
|
|
30269
|
+
const smask = new require_pdfObjects.PdfDict();
|
|
30270
|
+
smask.set("/Type", require_pdfObjects.PdfName.of("Mask"));
|
|
30271
|
+
smask.set("/S", require_pdfObjects.PdfName.of(subtype));
|
|
30272
|
+
smask.set("/G", options.groupXObject);
|
|
30273
|
+
if (subtype === "Luminosity" && options.backdropColor !== void 0 && options.backdropColor.length > 0) smask.set("/BC", require_pdfObjects.PdfArray.fromNumbers([...options.backdropColor]));
|
|
30274
|
+
if (options.transferFunction !== void 0) smask.set("/TR", options.transferFunction === "Identity" ? require_pdfObjects.PdfName.of("Identity") : options.transferFunction);
|
|
30275
|
+
const extGState = new require_pdfObjects.PdfDict();
|
|
30276
|
+
extGState.set("/Type", require_pdfObjects.PdfName.of("ExtGState"));
|
|
30277
|
+
extGState.set("/SMask", smask);
|
|
30278
|
+
return extGState;
|
|
30279
|
+
}
|
|
30280
|
+
/**
|
|
30281
|
+
* Build an `ExtGState` dictionary that clears any active soft mask by setting
|
|
30282
|
+
* `/SMask /None`. Apply this after a masked region to restore unmasked
|
|
30283
|
+
* painting.
|
|
30284
|
+
*
|
|
30285
|
+
* @returns An `ExtGState` {@link PdfDict} with `/SMask /None`.
|
|
30286
|
+
*/
|
|
30287
|
+
function buildSoftMaskNone() {
|
|
30288
|
+
const extGState = new require_pdfObjects.PdfDict();
|
|
30289
|
+
extGState.set("/Type", require_pdfObjects.PdfName.of("ExtGState"));
|
|
30290
|
+
extGState.set("/SMask", require_pdfObjects.PdfName.of("None"));
|
|
30291
|
+
return extGState;
|
|
30292
|
+
}
|
|
30293
|
+
//#endregion
|
|
30294
|
+
//#region src/core/imageMask.ts
|
|
30295
|
+
/**
|
|
30296
|
+
* @module core/imageMask
|
|
30297
|
+
*
|
|
30298
|
+
* Image masks and black-point compensation per ISO 32000-2 §8.9.6
|
|
30299
|
+
* (Masked images) and §8.6.5.9 (Black-point compensation).
|
|
30300
|
+
*
|
|
30301
|
+
* PDF supports three ways of masking an image XObject:
|
|
30302
|
+
*
|
|
30303
|
+
* - **Stencil mask** — a 1-bit-per-component `/ImageMask` image whose sample
|
|
30304
|
+
* values select which areas of the page are painted with the current fill
|
|
30305
|
+
* colour and which are left untouched (§8.9.6.2). The mask data is packed
|
|
30306
|
+
* one bit per sample, each row byte-aligned (`ceil(width / 8)` bytes per
|
|
30307
|
+
* row); the caller supplies the already-packed bytes.
|
|
30308
|
+
* - **Colour-key mask** — a `/Mask` array of `[min0 max0 min1 max1 …]`
|
|
30309
|
+
* integer ranges (two per colour component) that makes matching sample
|
|
30310
|
+
* colours transparent (§8.9.6.4).
|
|
30311
|
+
* - **Soft mask** — a separate DeviceGray image referenced from a base
|
|
30312
|
+
* image's `/SMask` entry, giving per-pixel opacity (§11.6.5.2).
|
|
30313
|
+
*
|
|
30314
|
+
* Black-point compensation (§8.6.5.9) is controlled through an ExtGState's
|
|
30315
|
+
* `/UseBlackPtComp` entry, which selects whether the conversion between
|
|
30316
|
+
* colour spaces maps source black to destination black.
|
|
30317
|
+
*
|
|
30318
|
+
* These are pure builders: they construct (and, for the stream variants,
|
|
30319
|
+
* register) PDF objects but do not wire them into a page or resource
|
|
30320
|
+
* dictionary — that is the caller's concern.
|
|
30321
|
+
*
|
|
30322
|
+
* Reference: ISO 32000-2:2020, §8.9.6 (Masked images), §8.6.5.9
|
|
30323
|
+
* (Black-point compensation).
|
|
30324
|
+
*/
|
|
30325
|
+
/**
|
|
30326
|
+
* Build a stencil mask: a 1-bit `/ImageMask` image XObject (§8.9.6.2).
|
|
30327
|
+
*
|
|
30328
|
+
* The returned stream has `/Type /XObject`, `/Subtype /Image`,
|
|
30329
|
+
* `/ImageMask true`, `/BitsPerComponent 1`, and the supplied `/Width` and
|
|
30330
|
+
* `/Height`. When a `decode` pair is given it is emitted as a `/Decode`
|
|
30331
|
+
* array, allowing the mask polarity to be inverted (`[1 0]`).
|
|
30332
|
+
*
|
|
30333
|
+
* The `bits` buffer must already be packed one bit per sample with each row
|
|
30334
|
+
* byte-aligned (`ceil(width / 8)` bytes per row); this builder stores it
|
|
30335
|
+
* verbatim and does not repack it.
|
|
30336
|
+
*
|
|
30337
|
+
* @param registry - Registry to register the stream into.
|
|
30338
|
+
* @param bits - Packed, byte-aligned 1-bpc mask data.
|
|
30339
|
+
* @param width - Image width in samples.
|
|
30340
|
+
* @param height - Image height in samples.
|
|
30341
|
+
* @param decode - Optional `[d0, d1]` decode pair.
|
|
30342
|
+
* @returns An indirect reference to the registered image XObject stream.
|
|
30343
|
+
*/
|
|
30344
|
+
function buildStencilMask(registry, bits, width, height, decode) {
|
|
30345
|
+
const dict = new require_pdfObjects.PdfDict();
|
|
30346
|
+
dict.set("/Type", require_pdfObjects.PdfName.of("XObject"));
|
|
30347
|
+
dict.set("/Subtype", require_pdfObjects.PdfName.of("Image"));
|
|
30348
|
+
dict.set("/ImageMask", require_pdfObjects.PdfBool.TRUE);
|
|
30349
|
+
dict.set("/BitsPerComponent", require_pdfObjects.PdfNumber.of(1));
|
|
30350
|
+
dict.set("/Width", require_pdfObjects.PdfNumber.of(width));
|
|
30351
|
+
dict.set("/Height", require_pdfObjects.PdfNumber.of(height));
|
|
30352
|
+
if (decode !== void 0) dict.set("/Decode", require_pdfObjects.PdfArray.fromNumbers([decode[0], decode[1]]));
|
|
30353
|
+
dict.set("/Length", require_pdfObjects.PdfNumber.of(bits.length));
|
|
30354
|
+
return registry.register(new require_pdfObjects.PdfStream(dict, bits));
|
|
30355
|
+
}
|
|
30356
|
+
/**
|
|
30357
|
+
* Build a colour-key masking array (§8.9.6.4).
|
|
30358
|
+
*
|
|
30359
|
+
* The `ranges` list holds two integers — a minimum and a maximum — per
|
|
30360
|
+
* colour component, laid out as `[min0 max0 min1 max1 …]`. Sample colours
|
|
30361
|
+
* whose every component falls within its range become transparent. The
|
|
30362
|
+
* returned {@link PdfArray} is assigned to a base image's `/Mask` entry.
|
|
30363
|
+
*
|
|
30364
|
+
* @param ranges - An even-length list of `[min, max]` integer pairs.
|
|
30365
|
+
* @returns A `/Mask` {@link PdfArray} of {@link PdfNumber}s.
|
|
30366
|
+
* @throws RangeError if `ranges` is empty or has an odd length.
|
|
30367
|
+
*/
|
|
30368
|
+
function buildColorKeyMask(ranges) {
|
|
30369
|
+
if (ranges.length === 0 || ranges.length % 2 !== 0) throw new RangeError(`colour-key mask requires a non-empty even number of values (min/max pairs); got ${ranges.length}`);
|
|
30370
|
+
return new require_pdfObjects.PdfArray(ranges.map((v) => require_pdfObjects.PdfNumber.of(v)));
|
|
30371
|
+
}
|
|
30372
|
+
/**
|
|
30373
|
+
* Build an image soft mask: a DeviceGray image XObject usable as a base
|
|
30374
|
+
* image's `/SMask` (§11.6.5.2).
|
|
30375
|
+
*
|
|
30376
|
+
* The returned stream has `/Type /XObject`, `/Subtype /Image`,
|
|
30377
|
+
* `/ColorSpace /DeviceGray`, the supplied `/Width` and `/Height`, and
|
|
30378
|
+
* `/BitsPerComponent` (defaulting to 8). Each grayscale sample provides the
|
|
30379
|
+
* opacity of the corresponding base-image pixel.
|
|
30380
|
+
*
|
|
30381
|
+
* @param registry - Registry to register the stream into.
|
|
30382
|
+
* @param gray - Grayscale opacity samples.
|
|
30383
|
+
* @param width - Image width in samples.
|
|
30384
|
+
* @param height - Image height in samples.
|
|
30385
|
+
* @param bitsPerComponent - Bits per sample; defaults to 8.
|
|
30386
|
+
* @returns An indirect reference to the registered soft-mask image XObject.
|
|
30387
|
+
*/
|
|
30388
|
+
function buildImageSoftMask(registry, gray, width, height, bitsPerComponent) {
|
|
30389
|
+
const dict = new require_pdfObjects.PdfDict();
|
|
30390
|
+
dict.set("/Type", require_pdfObjects.PdfName.of("XObject"));
|
|
30391
|
+
dict.set("/Subtype", require_pdfObjects.PdfName.of("Image"));
|
|
30392
|
+
dict.set("/Width", require_pdfObjects.PdfNumber.of(width));
|
|
30393
|
+
dict.set("/Height", require_pdfObjects.PdfNumber.of(height));
|
|
30394
|
+
dict.set("/ColorSpace", require_pdfObjects.PdfName.of("DeviceGray"));
|
|
30395
|
+
dict.set("/BitsPerComponent", require_pdfObjects.PdfNumber.of(bitsPerComponent ?? 8));
|
|
30396
|
+
dict.set("/Length", require_pdfObjects.PdfNumber.of(gray.length));
|
|
30397
|
+
return registry.register(new require_pdfObjects.PdfStream(dict, gray));
|
|
30398
|
+
}
|
|
30399
|
+
/**
|
|
30400
|
+
* Build an ExtGState that controls black-point compensation (§8.6.5.9).
|
|
30401
|
+
*
|
|
30402
|
+
* The returned dictionary has `/Type /ExtGState` and `/UseBlackPtComp` set
|
|
30403
|
+
* to the requested mode:
|
|
30404
|
+
*
|
|
30405
|
+
* - `Default` — leave the choice to the conforming reader.
|
|
30406
|
+
* - `ON` — always apply black-point compensation.
|
|
30407
|
+
* - `OFF` — never apply black-point compensation.
|
|
30408
|
+
*
|
|
30409
|
+
* @param mode - The `/UseBlackPtComp` mode.
|
|
30410
|
+
* @returns An ExtGState {@link PdfDict}.
|
|
30411
|
+
*/
|
|
30412
|
+
function buildBlackPointCompensationExtGState(mode) {
|
|
30413
|
+
const gs = new require_pdfObjects.PdfDict();
|
|
30414
|
+
gs.set("/Type", require_pdfObjects.PdfName.of("ExtGState"));
|
|
30415
|
+
gs.set("/UseBlackPtComp", require_pdfObjects.PdfName.of(mode));
|
|
30416
|
+
return gs;
|
|
30417
|
+
}
|
|
30418
|
+
//#endregion
|
|
29949
30419
|
//#region src/index.ts
|
|
29950
30420
|
/** Whether initWasm has already completed successfully. */
|
|
29951
30421
|
let wasmInitialized = false;
|
|
@@ -29972,15 +30442,15 @@ async function initWasm(options) {
|
|
|
29972
30442
|
if (wasmInitialized) return;
|
|
29973
30443
|
const inits = [];
|
|
29974
30444
|
if (options.deflate || options.deflateWasm) inits.push((async () => {
|
|
29975
|
-
const { initDeflateWasm } = await Promise.resolve().then(() => require("./pdfDocument-
|
|
30445
|
+
const { initDeflateWasm } = await Promise.resolve().then(() => require("./pdfDocument-Bh4ebDqE.cjs")).then((n) => n.libdeflateWasm_exports);
|
|
29976
30446
|
await initDeflateWasm(options.deflateWasm);
|
|
29977
30447
|
})());
|
|
29978
30448
|
if (options.png || options.pngWasm) inits.push((async () => {
|
|
29979
|
-
const { initPngWasm } = await Promise.resolve().then(() => require("./pdfDocument-
|
|
30449
|
+
const { initPngWasm } = await Promise.resolve().then(() => require("./pdfDocument-Bh4ebDqE.cjs")).then((n) => n.pngEmbed_exports);
|
|
29980
30450
|
await initPngWasm(options.pngWasm);
|
|
29981
30451
|
})());
|
|
29982
30452
|
if (options.fonts || options.fontWasm) inits.push((async () => {
|
|
29983
|
-
const { initSubsetWasm } = await Promise.resolve().then(() => require("./pdfDocument-
|
|
30453
|
+
const { initSubsetWasm } = await Promise.resolve().then(() => require("./pdfDocument-Bh4ebDqE.cjs")).then((n) => n.fontSubset_exports);
|
|
29984
30454
|
await initSubsetWasm(options.fontWasm);
|
|
29985
30455
|
})());
|
|
29986
30456
|
if (options.jpeg || options.jpegWasm) inits.push((async () => {
|
|
@@ -30411,6 +30881,18 @@ Object.defineProperty(exports, "assembleTiles", {
|
|
|
30411
30881
|
return assembleTiles;
|
|
30412
30882
|
}
|
|
30413
30883
|
});
|
|
30884
|
+
Object.defineProperty(exports, "attachAssociatedFiles", {
|
|
30885
|
+
enumerable: true,
|
|
30886
|
+
get: function() {
|
|
30887
|
+
return attachAssociatedFiles;
|
|
30888
|
+
}
|
|
30889
|
+
});
|
|
30890
|
+
Object.defineProperty(exports, "attachOutputIntents", {
|
|
30891
|
+
enumerable: true,
|
|
30892
|
+
get: function() {
|
|
30893
|
+
return attachOutputIntents;
|
|
30894
|
+
}
|
|
30895
|
+
});
|
|
30414
30896
|
Object.defineProperty(exports, "batchFlatten", {
|
|
30415
30897
|
enumerable: true,
|
|
30416
30898
|
get: function() {
|
|
@@ -30435,6 +30917,12 @@ Object.defineProperty(exports, "buildAfArray", {
|
|
|
30435
30917
|
return buildAfArray;
|
|
30436
30918
|
}
|
|
30437
30919
|
});
|
|
30920
|
+
Object.defineProperty(exports, "buildBlackPointCompensationExtGState", {
|
|
30921
|
+
enumerable: true,
|
|
30922
|
+
get: function() {
|
|
30923
|
+
return buildBlackPointCompensationExtGState;
|
|
30924
|
+
}
|
|
30925
|
+
});
|
|
30438
30926
|
Object.defineProperty(exports, "buildBoxDict", {
|
|
30439
30927
|
enumerable: true,
|
|
30440
30928
|
get: function() {
|
|
@@ -30465,6 +30953,12 @@ Object.defineProperty(exports, "buildCollection", {
|
|
|
30465
30953
|
return buildCollection;
|
|
30466
30954
|
}
|
|
30467
30955
|
});
|
|
30956
|
+
Object.defineProperty(exports, "buildColorKeyMask", {
|
|
30957
|
+
enumerable: true,
|
|
30958
|
+
get: function() {
|
|
30959
|
+
return buildColorKeyMask;
|
|
30960
|
+
}
|
|
30961
|
+
});
|
|
30468
30962
|
Object.defineProperty(exports, "buildDPartRoot", {
|
|
30469
30963
|
enumerable: true,
|
|
30470
30964
|
get: function() {
|
|
@@ -30495,6 +30989,12 @@ Object.defineProperty(exports, "buildDssDictionary", {
|
|
|
30495
30989
|
return buildDssDictionary;
|
|
30496
30990
|
}
|
|
30497
30991
|
});
|
|
30992
|
+
Object.defineProperty(exports, "buildEncryptedPayload", {
|
|
30993
|
+
enumerable: true,
|
|
30994
|
+
get: function() {
|
|
30995
|
+
return buildEncryptedPayload;
|
|
30996
|
+
}
|
|
30997
|
+
});
|
|
30498
30998
|
Object.defineProperty(exports, "buildFieldLockDict", {
|
|
30499
30999
|
enumerable: true,
|
|
30500
31000
|
get: function() {
|
|
@@ -30513,6 +31013,12 @@ Object.defineProperty(exports, "buildGtsPdfxVersion", {
|
|
|
30513
31013
|
return buildGtsPdfxVersion;
|
|
30514
31014
|
}
|
|
30515
31015
|
});
|
|
31016
|
+
Object.defineProperty(exports, "buildImageSoftMask", {
|
|
31017
|
+
enumerable: true,
|
|
31018
|
+
get: function() {
|
|
31019
|
+
return buildImageSoftMask;
|
|
31020
|
+
}
|
|
31021
|
+
});
|
|
30516
31022
|
Object.defineProperty(exports, "buildLab", {
|
|
30517
31023
|
enumerable: true,
|
|
30518
31024
|
get: function() {
|
|
@@ -30537,6 +31043,12 @@ Object.defineProperty(exports, "buildOutputIntent", {
|
|
|
30537
31043
|
return buildOutputIntent;
|
|
30538
31044
|
}
|
|
30539
31045
|
});
|
|
31046
|
+
Object.defineProperty(exports, "buildPageOutputIntent", {
|
|
31047
|
+
enumerable: true,
|
|
31048
|
+
get: function() {
|
|
31049
|
+
return buildPageOutputIntent;
|
|
31050
|
+
}
|
|
31051
|
+
});
|
|
30540
31052
|
Object.defineProperty(exports, "buildPdfA4Xmp", {
|
|
30541
31053
|
enumerable: true,
|
|
30542
31054
|
get: function() {
|
|
@@ -30591,6 +31103,24 @@ Object.defineProperty(exports, "buildSeparationColorSpace", {
|
|
|
30591
31103
|
return buildSeparationColorSpace;
|
|
30592
31104
|
}
|
|
30593
31105
|
});
|
|
31106
|
+
Object.defineProperty(exports, "buildSoftMaskGroupExtGState", {
|
|
31107
|
+
enumerable: true,
|
|
31108
|
+
get: function() {
|
|
31109
|
+
return buildSoftMaskGroupExtGState;
|
|
31110
|
+
}
|
|
31111
|
+
});
|
|
31112
|
+
Object.defineProperty(exports, "buildSoftMaskNone", {
|
|
31113
|
+
enumerable: true,
|
|
31114
|
+
get: function() {
|
|
31115
|
+
return buildSoftMaskNone;
|
|
31116
|
+
}
|
|
31117
|
+
});
|
|
31118
|
+
Object.defineProperty(exports, "buildStencilMask", {
|
|
31119
|
+
enumerable: true,
|
|
31120
|
+
get: function() {
|
|
31121
|
+
return buildStencilMask;
|
|
31122
|
+
}
|
|
31123
|
+
});
|
|
30594
31124
|
Object.defineProperty(exports, "buildThresholdHalftone", {
|
|
30595
31125
|
enumerable: true,
|
|
30596
31126
|
get: function() {
|
|
@@ -30615,6 +31145,12 @@ Object.defineProperty(exports, "buildType5Halftone", {
|
|
|
30615
31145
|
return buildType5Halftone;
|
|
30616
31146
|
}
|
|
30617
31147
|
});
|
|
31148
|
+
Object.defineProperty(exports, "buildUnencryptedWrapper", {
|
|
31149
|
+
enumerable: true,
|
|
31150
|
+
get: function() {
|
|
31151
|
+
return buildUnencryptedWrapper;
|
|
31152
|
+
}
|
|
31153
|
+
});
|
|
30618
31154
|
Object.defineProperty(exports, "buildVtDpm", {
|
|
30619
31155
|
enumerable: true,
|
|
30620
31156
|
get: function() {
|
|
@@ -31539,6 +32075,12 @@ Object.defineProperty(exports, "redactRegions", {
|
|
|
31539
32075
|
return redactRegions;
|
|
31540
32076
|
}
|
|
31541
32077
|
});
|
|
32078
|
+
Object.defineProperty(exports, "registerEmbeddedFile", {
|
|
32079
|
+
enumerable: true,
|
|
32080
|
+
get: function() {
|
|
32081
|
+
return registerEmbeddedFile;
|
|
32082
|
+
}
|
|
32083
|
+
});
|
|
31542
32084
|
Object.defineProperty(exports, "removeAllBookmarks", {
|
|
31543
32085
|
enumerable: true,
|
|
31544
32086
|
get: function() {
|
|
@@ -31870,4 +32412,4 @@ Object.defineProperty(exports, "wrapText", {
|
|
|
31870
32412
|
}
|
|
31871
32413
|
});
|
|
31872
32414
|
|
|
31873
|
-
//# sourceMappingURL=src-
|
|
32415
|
+
//# sourceMappingURL=src-Tb7wHOKz.cjs.map
|