@qrcommunication/gigapdf-lib 0.72.0 → 0.105.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 +640 -0
- package/dist/index.cjs +1374 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1227 -9
- package/dist/index.d.ts +1227 -9
- package/dist/index.js +1372 -15
- package/dist/index.js.map +1 -1
- package/gigapdf.wasm +0 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { loadDefaultWasmBytes } from "./node-fs.js";
|
|
3
|
+
function pdfVersionCode(v) {
|
|
4
|
+
return v === "2.0" ? 1 : 0;
|
|
5
|
+
}
|
|
3
6
|
var enc = new TextEncoder();
|
|
4
7
|
var dec = new TextDecoder();
|
|
5
8
|
var ALL_PERMISSIONS = {
|
|
@@ -122,6 +125,24 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
122
125
|
this.ex.gp_free(lenPtr, 4);
|
|
123
126
|
return s ? JSON.parse(s) : [];
|
|
124
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Like {@link _str} but distinguishes a **null** result (the export returned a
|
|
130
|
+
* null pointer — e.g. an `Option::None`) from a present-but-empty string.
|
|
131
|
+
* Returns `null` only for the null pointer; otherwise the decoded string.
|
|
132
|
+
*/
|
|
133
|
+
_strOrNull(call) {
|
|
134
|
+
const lenPtr = this.ex.gp_alloc(4);
|
|
135
|
+
const dataPtr = call(lenPtr);
|
|
136
|
+
if (dataPtr === 0) {
|
|
137
|
+
this.ex.gp_free(lenPtr, 4);
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
const len = this.dv().getUint32(lenPtr, true);
|
|
141
|
+
const s = dec.decode(this.u8().slice(dataPtr, dataPtr + len));
|
|
142
|
+
this.ex.gp_free(dataPtr, len);
|
|
143
|
+
this.ex.gp_free(lenPtr, 4);
|
|
144
|
+
return s;
|
|
145
|
+
}
|
|
125
146
|
/**
|
|
126
147
|
* Decode standard Base64 (RFC 4648) to bytes. Pure-JS table decode, so it
|
|
127
148
|
* works identically in Node and the browser with no dependency (used to turn
|
|
@@ -216,6 +237,23 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
216
237
|
this._free(pwPtr, b.length);
|
|
217
238
|
return handle === 0 ? null : new GigaPdfDoc(this, handle);
|
|
218
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Open a **public-key (certificate) encrypted** PDF (`/Filter /Adobe.PubSec`,
|
|
242
|
+
* ISO 32000-1 §7.6.5) with a recipient's DER `certificate` + PKCS#1 RSA
|
|
243
|
+
* `privateKey`. `null` if this key is not a recipient. Counterpart of
|
|
244
|
+
* {@link GigaPdfDoc.encryptForRecipients}.
|
|
245
|
+
*/
|
|
246
|
+
openWithPrivateKey(pdf, certificate, privateKey) {
|
|
247
|
+
const cP = this._toWasm(certificate);
|
|
248
|
+
const kP = this._toWasm(privateKey);
|
|
249
|
+
const handle = this._withBytes(
|
|
250
|
+
pdf,
|
|
251
|
+
(p, l) => this.ex.gp_open_with_private_key(p, l, cP, certificate.length, kP, privateKey.length)
|
|
252
|
+
);
|
|
253
|
+
this._free(cP, certificate.length);
|
|
254
|
+
this._free(kP, privateKey.length);
|
|
255
|
+
return handle === 0 ? null : new GigaPdfDoc(this, handle);
|
|
256
|
+
}
|
|
219
257
|
/**
|
|
220
258
|
* Inspect a PDF's encryption **without decrypting it** (no password needed):
|
|
221
259
|
* whether it has an `/Encrypt` dictionary, plus its `/P` permission bitmask
|
|
@@ -344,19 +382,34 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
344
382
|
);
|
|
345
383
|
}
|
|
346
384
|
/**
|
|
347
|
-
* Merge several PDFs into one by appending their pages in order.
|
|
348
|
-
*
|
|
349
|
-
*
|
|
385
|
+
* Merge several PDFs into one by appending their pages in order. Each input is
|
|
386
|
+
* either raw bytes (every page) or a {@link MergePart} `{ pdf, pages? }` that
|
|
387
|
+
* selects 1-based page numbers (ISO 32000-1 §7.7.3) — so the two forms can be
|
|
388
|
+
* mixed (e.g. `[whole, { pdf: b, pages: [1, 3] }]`). Returns an empty document
|
|
389
|
+
* for an empty list, or — when the only input is a whole PDF (no `pages`) —
|
|
390
|
+
* that input unchanged. Each subsequent part is appended onto the first via
|
|
350
391
|
* {@link GigaPdfDoc.appendPages}; the merged bytes are returned and the working
|
|
351
392
|
* document is closed.
|
|
352
393
|
*/
|
|
353
|
-
mergePdfs(
|
|
354
|
-
if (
|
|
355
|
-
|
|
356
|
-
const
|
|
394
|
+
mergePdfs(parts) {
|
|
395
|
+
if (parts.length === 0) return new Uint8Array(0);
|
|
396
|
+
const part = (p) => p instanceof Uint8Array ? { pdf: p } : p;
|
|
397
|
+
const first = part(parts[0]);
|
|
398
|
+
if (parts.length === 1 && first.pages === void 0) return first.pdf;
|
|
399
|
+
let seed = first.pdf;
|
|
400
|
+
if (first.pages !== void 0) {
|
|
401
|
+
const head = this.open(first.pdf);
|
|
402
|
+
try {
|
|
403
|
+
seed = head.extractPages(first.pages);
|
|
404
|
+
} finally {
|
|
405
|
+
head.close();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
const base = this.open(seed);
|
|
357
409
|
try {
|
|
358
|
-
for (let i = 1; i <
|
|
359
|
-
|
|
410
|
+
for (let i = 1; i < parts.length; i++) {
|
|
411
|
+
const p = part(parts[i]);
|
|
412
|
+
base.appendPages(p.pdf, p.pages);
|
|
360
413
|
}
|
|
361
414
|
return base.save();
|
|
362
415
|
} finally {
|
|
@@ -927,7 +980,48 @@ function frameBlobs(blobs) {
|
|
|
927
980
|
}
|
|
928
981
|
return out;
|
|
929
982
|
}
|
|
983
|
+
var AF_RELATIONSHIP_CODE = {
|
|
984
|
+
source: 0,
|
|
985
|
+
data: 1,
|
|
986
|
+
alternative: 2,
|
|
987
|
+
supplement: 3,
|
|
988
|
+
unspecified: 4
|
|
989
|
+
};
|
|
990
|
+
var PAGE_BOX_KINDS = ["media", "crop", "bleed", "trim", "art"];
|
|
991
|
+
var PAGE_LABEL_STYLE_TOKEN = {
|
|
992
|
+
decimal: "D",
|
|
993
|
+
romanLower: "r",
|
|
994
|
+
romanUpper: "R",
|
|
995
|
+
alphaLower: "a",
|
|
996
|
+
alphaUpper: "A",
|
|
997
|
+
none: "-"
|
|
998
|
+
};
|
|
999
|
+
var PAGE_TRANSITION_STYLES = [
|
|
1000
|
+
"split",
|
|
1001
|
+
"blinds",
|
|
1002
|
+
"box",
|
|
1003
|
+
"wipe",
|
|
1004
|
+
"dissolve",
|
|
1005
|
+
"glitter",
|
|
1006
|
+
"fly",
|
|
1007
|
+
"push",
|
|
1008
|
+
"cover",
|
|
1009
|
+
"uncover",
|
|
1010
|
+
"fade",
|
|
1011
|
+
"replace"
|
|
1012
|
+
];
|
|
930
1013
|
var RGB = (rgb) => rgb & 16777215;
|
|
1014
|
+
function cryptoRandom(n) {
|
|
1015
|
+
const c = globalThis.crypto;
|
|
1016
|
+
if (!c?.getRandomValues) {
|
|
1017
|
+
throw new Error(
|
|
1018
|
+
"this operation needs Web Crypto (globalThis.crypto.getRandomValues) or an explicit seed"
|
|
1019
|
+
);
|
|
1020
|
+
}
|
|
1021
|
+
const out = new Uint8Array(n);
|
|
1022
|
+
c.getRandomValues(out);
|
|
1023
|
+
return out;
|
|
1024
|
+
}
|
|
931
1025
|
function styleArgs(s = {}) {
|
|
932
1026
|
const hasBorder = s.border === null ? 0 : 1;
|
|
933
1027
|
const borderRgb = s.border == null ? 0 : s.border;
|
|
@@ -965,6 +1059,47 @@ var GigaPdfDoc = class {
|
|
|
965
1059
|
saveCompressed() {
|
|
966
1060
|
return this.g._buffer((o) => this.ex().gp_save_compressed(this.h, o));
|
|
967
1061
|
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Serialize with PDF 1.5+ **object streams** + a **cross-reference stream**
|
|
1064
|
+
* (ISO 32000-1 §7.5.7 / §7.5.8) — the most compact output. `objectStreams`
|
|
1065
|
+
* (default `true`) packs non-stream objects into compressed `/ObjStm`s (needs
|
|
1066
|
+
* the xref stream); `xrefStreams` (default `true`) writes a `/XRef` stream.
|
|
1067
|
+
* `version` selects the `%PDF-x.y` header banner (default `"1.7"`).
|
|
1068
|
+
* Uncompressed streams are Flate-compressed first, like {@link saveCompressed}.
|
|
1069
|
+
* Linearization (Fast Web View) is not performed.
|
|
1070
|
+
*/
|
|
1071
|
+
saveOptimized(opts = {}) {
|
|
1072
|
+
const obj = opts.objectStreams ?? true;
|
|
1073
|
+
const xref = opts.xrefStreams ?? true;
|
|
1074
|
+
const ver = pdfVersionCode(opts.version);
|
|
1075
|
+
return this.g._buffer(
|
|
1076
|
+
(o) => this.ex().gp_save_optimized(this.h, obj ? 1 : 0, xref ? 1 : 0, ver, o)
|
|
1077
|
+
);
|
|
1078
|
+
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Serialize as a **linearized** ("Fast Web View") PDF (ISO 32000-1 Annex F).
|
|
1081
|
+
*
|
|
1082
|
+
* The first page and only the objects needed to render it — together with a
|
|
1083
|
+
* `/Linearized` parameter dictionary and a primary hint stream — are written at
|
|
1084
|
+
* the **front** of the file, so a web viewer can display page 1 before the rest
|
|
1085
|
+
* of the document has downloaded (progressive rendering / byte-range serving).
|
|
1086
|
+
* The remaining pages follow, then a main cross-reference table; the first-page
|
|
1087
|
+
* cross-reference section chains to it via `/Prev`. Streams are Flate-compressed
|
|
1088
|
+
* first (like {@link saveCompressed}) and embedded fonts are subset.
|
|
1089
|
+
*
|
|
1090
|
+
* Falls back to the plain {@link save} output if the document cannot be
|
|
1091
|
+
* linearized (no catalog / page tree / zero pages). `version` selects the
|
|
1092
|
+
* `%PDF-x.y` header banner (default `"1.7"`).
|
|
1093
|
+
*/
|
|
1094
|
+
toLinearized(version = "1.7") {
|
|
1095
|
+
return this.g._buffer(
|
|
1096
|
+
(o) => this.ex().gp_to_linearized(this.h, pdfVersionCode(version), o)
|
|
1097
|
+
);
|
|
1098
|
+
}
|
|
1099
|
+
/** Alias of {@link toLinearized} — serialize as a linearized (Fast Web View) PDF. */
|
|
1100
|
+
saveLinearized(version = "1.7") {
|
|
1101
|
+
return this.toLinearized(version);
|
|
1102
|
+
}
|
|
968
1103
|
// text intelligence
|
|
969
1104
|
textRuns(page) {
|
|
970
1105
|
return this.g._json((o) => this.ex().gp_text_runs_json(this.h, page, o));
|
|
@@ -1211,6 +1346,212 @@ var GigaPdfDoc = class {
|
|
|
1211
1346
|
opacity
|
|
1212
1347
|
) === 0;
|
|
1213
1348
|
}
|
|
1349
|
+
/**
|
|
1350
|
+
* Paint a **linear** or **radial** gradient over `rect` on `page` (ISO 32000-1
|
|
1351
|
+
* §8.7.4 shading + §8.7.3 pattern). `coords` is `[x0,y0,x1,y1]` for `"linear"`
|
|
1352
|
+
* or `[x0,y0,r0,x1,y1,r1]` for `"radial"`; `stops` is ≥ 2 colour stops
|
|
1353
|
+
* (`offset` 0…1, `rgb` packed `0xRRGGBB`). `extend` (default `[true,true]`)
|
|
1354
|
+
* sets `/Extend`; `opacity` (default `1`) is the fill alpha.
|
|
1355
|
+
*
|
|
1356
|
+
* @example
|
|
1357
|
+
* doc.addGradient(1, {
|
|
1358
|
+
* kind: "linear", coords: [50, 50, 250, 50],
|
|
1359
|
+
* stops: [{ offset: 0, rgb: 0xff0000 }, { offset: 1, rgb: 0x0000ff }],
|
|
1360
|
+
* rect: { x: 50, y: 40, w: 200, h: 60 },
|
|
1361
|
+
* });
|
|
1362
|
+
*/
|
|
1363
|
+
addGradient(page, spec) {
|
|
1364
|
+
const kind = spec.kind === "radial" ? 1 : 0;
|
|
1365
|
+
const offsets = spec.stops.map((s) => s.offset);
|
|
1366
|
+
const colors = spec.stops.map((s) => RGB(s.rgb));
|
|
1367
|
+
const [es, ee] = spec.extend ?? [true, true];
|
|
1368
|
+
const opacity = spec.opacity ?? 1;
|
|
1369
|
+
const r = spec.rect;
|
|
1370
|
+
return this.g._withF64(
|
|
1371
|
+
spec.coords,
|
|
1372
|
+
(cp, cc) => this.g._withF64(
|
|
1373
|
+
offsets,
|
|
1374
|
+
(op, _oc) => this.g._withU32(
|
|
1375
|
+
colors,
|
|
1376
|
+
(clp, _clc) => this.ex().gp_add_gradient(
|
|
1377
|
+
this.h,
|
|
1378
|
+
page,
|
|
1379
|
+
kind,
|
|
1380
|
+
cp,
|
|
1381
|
+
cc,
|
|
1382
|
+
op,
|
|
1383
|
+
clp,
|
|
1384
|
+
offsets.length,
|
|
1385
|
+
r.x,
|
|
1386
|
+
r.y,
|
|
1387
|
+
r.w,
|
|
1388
|
+
r.h,
|
|
1389
|
+
es ? 1 : 0,
|
|
1390
|
+
ee ? 1 : 0,
|
|
1391
|
+
opacity
|
|
1392
|
+
)
|
|
1393
|
+
)
|
|
1394
|
+
)
|
|
1395
|
+
) === 0;
|
|
1396
|
+
}
|
|
1397
|
+
/**
|
|
1398
|
+
* Encode a {@link Color} into the ABI's `(kind, comps, name, profile)` buffers
|
|
1399
|
+
* and invoke `fn` with the resulting pointers. Internal.
|
|
1400
|
+
*/
|
|
1401
|
+
_color(color, fn) {
|
|
1402
|
+
let kind;
|
|
1403
|
+
let comps;
|
|
1404
|
+
let name = "";
|
|
1405
|
+
let profile = null;
|
|
1406
|
+
switch (color.space) {
|
|
1407
|
+
case "cmyk":
|
|
1408
|
+
kind = 1;
|
|
1409
|
+
comps = [color.c, color.m, color.y, color.k];
|
|
1410
|
+
break;
|
|
1411
|
+
case "gray":
|
|
1412
|
+
kind = 2;
|
|
1413
|
+
comps = [color.gray];
|
|
1414
|
+
break;
|
|
1415
|
+
case "separation":
|
|
1416
|
+
kind = 3;
|
|
1417
|
+
comps = [color.tint, ...color.cmyk];
|
|
1418
|
+
name = color.name;
|
|
1419
|
+
break;
|
|
1420
|
+
case "icc":
|
|
1421
|
+
kind = 4;
|
|
1422
|
+
comps = color.components;
|
|
1423
|
+
profile = color.profile;
|
|
1424
|
+
break;
|
|
1425
|
+
default: {
|
|
1426
|
+
const c = RGB(color.rgb);
|
|
1427
|
+
kind = 0;
|
|
1428
|
+
comps = [(c >> 16 & 255) / 255, (c >> 8 & 255) / 255, (c & 255) / 255];
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
return this.g._withF64(
|
|
1432
|
+
comps,
|
|
1433
|
+
(cp, cc) => this.g._withOptStr(
|
|
1434
|
+
name,
|
|
1435
|
+
(np, nl) => profile ? this.g._withBytes(profile, (pp, pl) => fn(kind, cp, cc, np, nl, pp, pl)) : fn(kind, cp, cc, np, nl, 0, 0)
|
|
1436
|
+
)
|
|
1437
|
+
);
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Fill a rectangle with `color` in **any** colour space — the press-ready
|
|
1441
|
+
* counterpart of {@link addRectangle} (CMYK, spot `Separation`, gray, ICC).
|
|
1442
|
+
*
|
|
1443
|
+
* @example
|
|
1444
|
+
* doc.addFilledRectangle(1, { x: 40, y: 700, w: 200, h: 40 },
|
|
1445
|
+
* { space: "cmyk", c: 0.1, m: 0.8, y: 0.9, k: 0 });
|
|
1446
|
+
*/
|
|
1447
|
+
addFilledRectangle(page, rect, color, opacity = 1) {
|
|
1448
|
+
return this._color(
|
|
1449
|
+
color,
|
|
1450
|
+
(kind, cp, cc, np, nl, pp, pl) => this.ex().gp_add_filled_rectangle(
|
|
1451
|
+
this.h,
|
|
1452
|
+
page,
|
|
1453
|
+
rect.x,
|
|
1454
|
+
rect.y,
|
|
1455
|
+
rect.w,
|
|
1456
|
+
rect.h,
|
|
1457
|
+
kind,
|
|
1458
|
+
cp,
|
|
1459
|
+
cc,
|
|
1460
|
+
np,
|
|
1461
|
+
nl,
|
|
1462
|
+
pp,
|
|
1463
|
+
pl,
|
|
1464
|
+
opacity
|
|
1465
|
+
)
|
|
1466
|
+
) === 0;
|
|
1467
|
+
}
|
|
1468
|
+
/**
|
|
1469
|
+
* Fill a polygon through flat `[x0,y0,x1,y1,…]` `points` (≥ 3 vertices) with
|
|
1470
|
+
* `color` in any colour space. The path is closed automatically.
|
|
1471
|
+
*/
|
|
1472
|
+
addFilledPolygon(page, points, color, opacity = 1) {
|
|
1473
|
+
return this.g._withF64(
|
|
1474
|
+
points,
|
|
1475
|
+
(ptsPtr, ptsCount) => this._color(
|
|
1476
|
+
color,
|
|
1477
|
+
(kind, cp, cc, np, nl, pp, pl) => this.ex().gp_add_filled_polygon(
|
|
1478
|
+
this.h,
|
|
1479
|
+
page,
|
|
1480
|
+
ptsPtr,
|
|
1481
|
+
ptsCount,
|
|
1482
|
+
kind,
|
|
1483
|
+
cp,
|
|
1484
|
+
cc,
|
|
1485
|
+
np,
|
|
1486
|
+
nl,
|
|
1487
|
+
pp,
|
|
1488
|
+
pl,
|
|
1489
|
+
opacity
|
|
1490
|
+
)
|
|
1491
|
+
)
|
|
1492
|
+
) === 0;
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* Draw a base-14 text run in **any** colour space — the press-ready
|
|
1496
|
+
* counterpart of {@link addTextStandard}. `font` is a base-14 family
|
|
1497
|
+
* (`Helvetica`, `Times-Roman`, `Courier`, …).
|
|
1498
|
+
*/
|
|
1499
|
+
addTextColor(page, x, y, size, text, font, color, opts = {}) {
|
|
1500
|
+
const { opacity = 1, rotation = 0, underline = false, strikethrough = false } = opts;
|
|
1501
|
+
return this.g._withStr(
|
|
1502
|
+
text,
|
|
1503
|
+
(tp, tl) => this.g._withStr(
|
|
1504
|
+
font,
|
|
1505
|
+
(fp, fl) => this._color(
|
|
1506
|
+
color,
|
|
1507
|
+
(kind, cp, cc, np, nl, pp, pl) => this.ex().gp_add_text_color(
|
|
1508
|
+
this.h,
|
|
1509
|
+
page,
|
|
1510
|
+
x,
|
|
1511
|
+
y,
|
|
1512
|
+
size,
|
|
1513
|
+
tp,
|
|
1514
|
+
tl,
|
|
1515
|
+
fp,
|
|
1516
|
+
fl,
|
|
1517
|
+
kind,
|
|
1518
|
+
cp,
|
|
1519
|
+
cc,
|
|
1520
|
+
np,
|
|
1521
|
+
nl,
|
|
1522
|
+
pp,
|
|
1523
|
+
pl,
|
|
1524
|
+
opacity,
|
|
1525
|
+
rotation,
|
|
1526
|
+
underline ? 1 : 0,
|
|
1527
|
+
strikethrough ? 1 : 0
|
|
1528
|
+
)
|
|
1529
|
+
)
|
|
1530
|
+
)
|
|
1531
|
+
) === 0;
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* Turn **overprint** on/off for content drawn **after** this call (`/op` fill,
|
|
1535
|
+
* `/OP` stroke, `/OPM` mode — `0` independent colorants, `1` non-erasing).
|
|
1536
|
+
* Essential for prepress black-overprint / trapping.
|
|
1537
|
+
*/
|
|
1538
|
+
setOverprint(page, fill, stroke, mode = 1) {
|
|
1539
|
+
return this.ex().gp_set_overprint(this.h, page, fill ? 1 : 0, stroke ? 1 : 0, mode) === 0;
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Add a document-level **OutputIntent** embedding the ICC `profile` (its `/N`
|
|
1543
|
+
* is read from the profile), with `condition` as the output-condition
|
|
1544
|
+
* identifier (e.g. `"Coated FOGRA39"`). Decoupled from the PDF/A path.
|
|
1545
|
+
*/
|
|
1546
|
+
addOutputIntent(profile, condition) {
|
|
1547
|
+
return this.g._withBytes(
|
|
1548
|
+
profile,
|
|
1549
|
+
(pp, pl) => this.g._withStr(
|
|
1550
|
+
condition,
|
|
1551
|
+
(cp, cl) => this.ex().gp_add_output_intent(this.h, pp, pl, cp, cl)
|
|
1552
|
+
)
|
|
1553
|
+
) === 0;
|
|
1554
|
+
}
|
|
1214
1555
|
/**
|
|
1215
1556
|
* Draw a polyline/polygon through flat `[x0,y0,x1,y1,…]` points. `close` joins
|
|
1216
1557
|
* the last vertex back to the first. `0xRRGGBB` colours, or `null` to omit.
|
|
@@ -1267,6 +1608,27 @@ var GigaPdfDoc = class {
|
|
|
1267
1608
|
(p, l) => this.ex().gp_add_image(this.h, page, p, l, x, y, w, h, opacity)
|
|
1268
1609
|
) === 0;
|
|
1269
1610
|
}
|
|
1611
|
+
/**
|
|
1612
|
+
* Replace the pixels of an **existing image XObject in place** — swap a logo or
|
|
1613
|
+
* photo while every reference to it stays intact (ISO 32000-1 §8.9). `index` is
|
|
1614
|
+
* the **unified element index** of an image on `page`, exactly the `index`
|
|
1615
|
+
* reported by {@link imageElements} (and accepted by {@link removeElement} /
|
|
1616
|
+
* {@link transformElement}); `data` is a fresh PNG or JPEG.
|
|
1617
|
+
*
|
|
1618
|
+
* Unlike a delete-then-re-add, the image keeps its object number, **every `/Do`
|
|
1619
|
+
* placement, and its position / scale / rotation / clip matrix** — only the
|
|
1620
|
+
* stream bytes and the image dictionary (`/Width`, `/Height`, `/ColorSpace`,
|
|
1621
|
+
* `/BitsPerComponent`, `/Filter`) are rewritten. The new raster is re-encoded
|
|
1622
|
+
* through the same path as {@link addImage} (PNG alpha → a fresh `/SMask`; JPEG
|
|
1623
|
+
* → `/DCTDecode` passthrough). It need not match the old pixel size — it is
|
|
1624
|
+
* drawn into the same box (transform the element first to re-fit it).
|
|
1625
|
+
*
|
|
1626
|
+
* Returns `false` if `page`/`index` doesn't resolve to a top-level image, or the
|
|
1627
|
+
* bytes aren't a decodable PNG/JPEG.
|
|
1628
|
+
*/
|
|
1629
|
+
replaceImage(page, index, data) {
|
|
1630
|
+
return this.g._withBytes(data, (p, l) => this.ex().gp_replace_image(this.h, page, index, p, l)) === 0;
|
|
1631
|
+
}
|
|
1270
1632
|
/**
|
|
1271
1633
|
* Stamp an **image watermark** across pages from raw image bytes. Accepts the
|
|
1272
1634
|
* same five formats the engine decodes — **PNG, JPEG, WebP, GIF, AVIF**. The
|
|
@@ -1363,8 +1725,25 @@ var GigaPdfDoc = class {
|
|
|
1363
1725
|
movePage(from, to) {
|
|
1364
1726
|
return this.ex().gp_move_page(this.h, from, to) === 0;
|
|
1365
1727
|
}
|
|
1366
|
-
|
|
1367
|
-
|
|
1728
|
+
/**
|
|
1729
|
+
* Append pages of another PDF onto this document. With no `pages`, every page
|
|
1730
|
+
* is appended (powers *merge*). With `pages` — 1-based page numbers, in the
|
|
1731
|
+
* order given — only that selection is brought in (ISO 32000-1 §7.7.3), each
|
|
1732
|
+
* page keeping its content, resources, annotations and box geometry. Numbers
|
|
1733
|
+
* out of range are skipped; an empty/all-out-of-range selection returns
|
|
1734
|
+
* `false`.
|
|
1735
|
+
*/
|
|
1736
|
+
appendPages(otherPdf, pages) {
|
|
1737
|
+
if (pages === void 0) {
|
|
1738
|
+
return this.g._withBytes(otherPdf, (p, l) => this.ex().gp_append_pages(this.h, p, l)) === 0;
|
|
1739
|
+
}
|
|
1740
|
+
return this.g._withBytes(
|
|
1741
|
+
otherPdf,
|
|
1742
|
+
(bp, bl) => this.g._withU32(
|
|
1743
|
+
pages,
|
|
1744
|
+
(pp, pc) => this.ex().gp_append_pages_subset(this.h, bp, bl, pp, pc)
|
|
1745
|
+
)
|
|
1746
|
+
) === 0;
|
|
1368
1747
|
}
|
|
1369
1748
|
/**
|
|
1370
1749
|
* Add an invisible (text render mode 3) standard-Helvetica text layer to
|
|
@@ -1407,10 +1786,71 @@ var GigaPdfDoc = class {
|
|
|
1407
1786
|
(p, c) => this.g._buffer((o) => this.ex().gp_extract_pages(this.h, p, c, o))
|
|
1408
1787
|
);
|
|
1409
1788
|
}
|
|
1410
|
-
/**
|
|
1789
|
+
/**
|
|
1790
|
+
* Resize a page's `/MediaBox` to `width`×`height` points — **box geometry
|
|
1791
|
+
* only**. The drawn content keeps its own coordinates (it is *not* rescaled to
|
|
1792
|
+
* the new box, so it may clip or float). To scale the page content along with
|
|
1793
|
+
* the box (keeping annotations aligned) use {@link scalePageContent} or
|
|
1794
|
+
* {@link scalePageTo}; for large-format authoring see {@link setUserUnit}.
|
|
1795
|
+
*/
|
|
1411
1796
|
resizePage(page, width, height) {
|
|
1412
1797
|
return this.ex().gp_resize_page(this.h, page, width, height) === 0;
|
|
1413
1798
|
}
|
|
1799
|
+
/**
|
|
1800
|
+
* Scale a page's **content** uniformly by `factor` about the page origin (ISO
|
|
1801
|
+
* 32000-1 §8.3.4) — a true zoom of the whole page, not just the box. Three
|
|
1802
|
+
* things move together: (1) the content stream is wrapped in
|
|
1803
|
+
* `q <factor 0 0 factor 0 0> cm … Q`; (2) `/MediaBox` and `/CropBox` (resolved
|
|
1804
|
+
* through inheritance) plus any locally declared `/BleedBox`/`/TrimBox`/
|
|
1805
|
+
* `/ArtBox` are scaled about the origin; (3) every annotation `/Rect` is scaled,
|
|
1806
|
+
* so widget/stamp appearances — mapped from their `/BBox` into the `/Rect` per
|
|
1807
|
+
* §12.5.5 — rescale to stay aligned automatically. `factor` must be finite and
|
|
1808
|
+
* positive. `false` on engine error (bad page number / non-positive factor).
|
|
1809
|
+
*/
|
|
1810
|
+
scalePageContent(page, factor) {
|
|
1811
|
+
return this.ex().gp_scale_page_content(this.h, page, factor) === 0;
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* Anisotropic {@link scalePageContent}: scale a page's content by `sx`
|
|
1815
|
+
* horizontally and `sy` vertically about the origin, scaling the boxes and
|
|
1816
|
+
* annotation `/Rect`s by the same factors. Both must be finite and positive.
|
|
1817
|
+
* `false` on engine error.
|
|
1818
|
+
*/
|
|
1819
|
+
scalePageContentXY(page, sx, sy) {
|
|
1820
|
+
return this.ex().gp_scale_page_content_xy(this.h, page, sx, sy) === 0;
|
|
1821
|
+
}
|
|
1822
|
+
/**
|
|
1823
|
+
* Scale a page's content to **fit within** `width`×`height` points (shrink- or
|
|
1824
|
+
* grow-to-fit), preserving aspect ratio — equivalent to {@link scalePageContent}
|
|
1825
|
+
* with `min(width / currentWidth, height / currentHeight)` over the page's
|
|
1826
|
+
* displayed size (`/MediaBox` with `/Rotate` applied). Returns the uniform
|
|
1827
|
+
* factor applied, or `null` on engine error (bad page number, non-positive
|
|
1828
|
+
* target, or zero-area page).
|
|
1829
|
+
*/
|
|
1830
|
+
scalePageTo(page, width, height) {
|
|
1831
|
+
const factor = this.ex().gp_scale_page_to(this.h, page, width, height);
|
|
1832
|
+
return factor < 0 ? null : factor;
|
|
1833
|
+
}
|
|
1834
|
+
/**
|
|
1835
|
+
* Set a page's `/UserUnit` (ISO 32000-1 §14.11.2) for **large-format
|
|
1836
|
+
* authoring**: one default user-space unit becomes `unit`⁄72 inch, so the same
|
|
1837
|
+
* coordinates render larger (e.g. `2.0` doubles the physical size, lifting the
|
|
1838
|
+
* ~200-inch coordinate ceiling). `1.0` is the default and removes the key. This
|
|
1839
|
+
* is distinct from {@link scalePageContent}: it rescales the coordinate system
|
|
1840
|
+
* (a viewer-level zoom of the medium), not the content or boxes. `unit` must be
|
|
1841
|
+
* finite and positive. `false` on engine error.
|
|
1842
|
+
*/
|
|
1843
|
+
setUserUnit(page, unit) {
|
|
1844
|
+
return this.ex().gp_set_user_unit(this.h, page, unit) === 0;
|
|
1845
|
+
}
|
|
1846
|
+
/**
|
|
1847
|
+
* A page's `/UserUnit` (ISO 32000-1 §14.11.2), defaulting to `1.0` when absent.
|
|
1848
|
+
* Returns `null` on engine error (bad page number).
|
|
1849
|
+
*/
|
|
1850
|
+
pageUserUnit(page) {
|
|
1851
|
+
const unit = this.ex().gp_page_user_unit(this.h, page);
|
|
1852
|
+
return unit < 0 ? null : unit;
|
|
1853
|
+
}
|
|
1414
1854
|
/** Insert a blank page after the 1-based `after` page (0 = front); returns its id. */
|
|
1415
1855
|
addPage(width, height, after = 0) {
|
|
1416
1856
|
return this.ex().gp_add_page(this.h, width, height, after);
|
|
@@ -1419,6 +1859,56 @@ var GigaPdfDoc = class {
|
|
|
1419
1859
|
copyPage(page) {
|
|
1420
1860
|
return this.ex().gp_copy_page(this.h, page);
|
|
1421
1861
|
}
|
|
1862
|
+
/**
|
|
1863
|
+
* N-up imposition (ISO 32000-1 §8.10): draw the **content** of the 1-based
|
|
1864
|
+
* `source` page, scaled and translated, onto the 1-based `target` page — the
|
|
1865
|
+
* basis for 2-up/4-up, booklets, contact sheets and page-on-page stamping. The
|
|
1866
|
+
* source page becomes a Form XObject (its content + `/Resources`, so its fonts
|
|
1867
|
+
* and images come along) and is drawn with `q <cm> /Fmn Do Q` appended to the
|
|
1868
|
+
* target. `(x, y)` is where the visible page's lower-left corner lands and
|
|
1869
|
+
* `(scaleX, scaleY)` scale the page **as displayed** (its `/MediaBox` origin
|
|
1870
|
+
* and `/Rotate` are absorbed into the matrix). Wrapped in `q`/`Q`, so it never
|
|
1871
|
+
* disturbs existing target content and is **composable** — call it repeatedly
|
|
1872
|
+
* (different sources and/or cells) to build an N-up sheet. `source` and
|
|
1873
|
+
* `target` may be the same page. `false` on engine error (bad page number).
|
|
1874
|
+
*/
|
|
1875
|
+
placePage(target, source, x, y, scaleX, scaleY) {
|
|
1876
|
+
return this.ex().gp_place_page(this.h, target, source, x, y, scaleX, scaleY) === 0;
|
|
1877
|
+
}
|
|
1878
|
+
/**
|
|
1879
|
+
* Place `source` onto `target` (both 1-based) using an explicit content-stream
|
|
1880
|
+
* matrix `[a, b, c, d, e, f]` — the low-level primitive behind
|
|
1881
|
+
* {@link placePage} for full control of the affine (shear, arbitrary rotation,
|
|
1882
|
+
* reflection). The matrix maps the source page's form space (its user space,
|
|
1883
|
+
* including the `/MediaBox` origin) to the target; unlike {@link placePage} no
|
|
1884
|
+
* origin/rotation normalisation is applied, so identity draws the source 1:1
|
|
1885
|
+
* at the target origin. `false` on engine error.
|
|
1886
|
+
*/
|
|
1887
|
+
placePageMatrix(target, source, matrix) {
|
|
1888
|
+
const [a, b, c, d, e, f] = matrix;
|
|
1889
|
+
return this.ex().gp_place_page_matrix(this.h, target, source, a, b, c, d, e, f) === 0;
|
|
1890
|
+
}
|
|
1891
|
+
/**
|
|
1892
|
+
* Impose **all** existing pages `cols × rows` per sheet onto freshly added
|
|
1893
|
+
* sheets (2-up, 4-up, booklet thumbnails, contact sheets). Pages go
|
|
1894
|
+
* left-to-right, top-to-bottom; each is scaled uniformly to fit its cell
|
|
1895
|
+
* (aspect preserved) and centred. The new sheets are appended after the last
|
|
1896
|
+
* original page and the **originals are removed**, leaving only the imposed
|
|
1897
|
+
* sheets. Returns the number of sheets produced (negative on error: `cols`/
|
|
1898
|
+
* `rows` 0, or an empty document). `sheetWidth`/`sheetHeight` default to A4
|
|
1899
|
+
* portrait; `margin`/`gutter` to 14 pt.
|
|
1900
|
+
*/
|
|
1901
|
+
nUp(cols, rows, opts = {}) {
|
|
1902
|
+
return this.ex().gp_n_up(
|
|
1903
|
+
this.h,
|
|
1904
|
+
cols,
|
|
1905
|
+
rows,
|
|
1906
|
+
opts.sheetWidth ?? 595.28,
|
|
1907
|
+
opts.sheetHeight ?? 841.89,
|
|
1908
|
+
opts.margin ?? 14,
|
|
1909
|
+
opts.gutter ?? 14
|
|
1910
|
+
);
|
|
1911
|
+
}
|
|
1422
1912
|
/** A page's size (points) and `/Rotate` (0/90/180/270). */
|
|
1423
1913
|
pageInfo(page) {
|
|
1424
1914
|
return this.g._json((o) => this.ex().gp_page_info_json(this.h, page, o));
|
|
@@ -1438,6 +1928,154 @@ var GigaPdfDoc = class {
|
|
|
1438
1928
|
setPageMargins(page, m) {
|
|
1439
1929
|
return this.ex().gp_set_page_margins(this.h, page, m.top, m.right, m.bottom, m.left) === 0;
|
|
1440
1930
|
}
|
|
1931
|
+
/**
|
|
1932
|
+
* Store an **opaque** JSON string as the document's GigaPDF editor-metadata
|
|
1933
|
+
* sidecar — private editor state that travels with the PDF (catalog
|
|
1934
|
+
* `/GigaPDF /EditorMeta`, a FlateDecode-compressed stream). It is ignored by
|
|
1935
|
+
* every standard PDF reader and the round-trip survives save/open. Pass a JSON
|
|
1936
|
+
* **object** if you also use {@link setEditorMargins} (which read-modify-writes
|
|
1937
|
+
* that object's `margins` key). Returns `true` on success.
|
|
1938
|
+
*/
|
|
1939
|
+
setEditorMeta(json) {
|
|
1940
|
+
return this.g._withStr(json, (p, l) => this.ex().gp_set_editor_meta(this.h, p, l)) === 0;
|
|
1941
|
+
}
|
|
1942
|
+
/**
|
|
1943
|
+
* The document's GigaPDF editor-metadata sidecar string (set by
|
|
1944
|
+
* {@link setEditorMeta}), or `null` when the document carries none.
|
|
1945
|
+
*/
|
|
1946
|
+
editorMeta() {
|
|
1947
|
+
return this.g._strOrNull((o) => this.ex().gp_editor_meta(this.h, o));
|
|
1948
|
+
}
|
|
1949
|
+
/**
|
|
1950
|
+
* Record the editor's per-page **display** margins (points) in the
|
|
1951
|
+
* editor-metadata sidecar (under `margins`, keyed by page) **without touching
|
|
1952
|
+
* `/CropBox` or `/MediaBox`** — distinct from {@link setPageMargins}, which
|
|
1953
|
+
* performs a real visible recrop. Any other host keys in the sidecar are
|
|
1954
|
+
* preserved. Returns `true` on success.
|
|
1955
|
+
*/
|
|
1956
|
+
setEditorMargins(page, m) {
|
|
1957
|
+
return this.ex().gp_set_editor_margins(this.h, page, m.top, m.right, m.bottom, m.left) === 0;
|
|
1958
|
+
}
|
|
1959
|
+
/**
|
|
1960
|
+
* The editor's per-page display margins (points) recorded for `page` by
|
|
1961
|
+
* {@link setEditorMargins}, or `null` when none were stored. Reads only the
|
|
1962
|
+
* sidecar — never `/CropBox`.
|
|
1963
|
+
*/
|
|
1964
|
+
editorMargins(page) {
|
|
1965
|
+
return this.g._jsonOrNull((o) => this.ex().gp_editor_margins(this.h, page, o));
|
|
1966
|
+
}
|
|
1967
|
+
/**
|
|
1968
|
+
* All five page boundary boxes (`media`/`crop`/`bleed`/`trim`/`art`) for the
|
|
1969
|
+
* 1-based `page`, each as `[x0, y0, x1, y1]` in points, with ISO 32000-1
|
|
1970
|
+
* inheritance and defaults applied. See {@link PageBoxes} for the exact
|
|
1971
|
+
* default chain and the `declared` flags.
|
|
1972
|
+
*/
|
|
1973
|
+
getPageBoxes(page) {
|
|
1974
|
+
return this.g._json((o) => this.ex().gp_page_boxes_json(this.h, page, o));
|
|
1975
|
+
}
|
|
1976
|
+
/**
|
|
1977
|
+
* Set one of a page's boundary boxes. `kind` is one of {@link PAGE_BOX_KINDS}
|
|
1978
|
+
* and `box` is given as `{ x, y, w, h }` (origin + size, points); it is written
|
|
1979
|
+
* as `[x, y, x+w, y+h]`, normalised so reversed sizes are accepted. Sibling
|
|
1980
|
+
* boxes are preserved. Returns `true` on success, `false` for an unknown kind,
|
|
1981
|
+
* a degenerate box (zero/negative area), or a bad page number.
|
|
1982
|
+
*
|
|
1983
|
+
* Setting `"trim"`/`"bleed"` is the prerequisite for PDF/X and commercial-print
|
|
1984
|
+
* (imposition, bleed, finished-size) pipelines.
|
|
1985
|
+
*/
|
|
1986
|
+
setPageBox(page, kind, box) {
|
|
1987
|
+
const k = PAGE_BOX_KINDS.indexOf(kind);
|
|
1988
|
+
if (k < 0) return false;
|
|
1989
|
+
return this.ex().gp_set_page_box(this.h, page, k, box.x, box.y, box.x + box.w, box.y + box.h) === 0;
|
|
1990
|
+
}
|
|
1991
|
+
/**
|
|
1992
|
+
* The document's page-label ranges (`/PageLabels`, ISO 32000-1 §12.4.2), sorted
|
|
1993
|
+
* by `startPage` (1-based). Empty when the document declares no page labels.
|
|
1994
|
+
*/
|
|
1995
|
+
getPageLabels() {
|
|
1996
|
+
return this.g._json((o) => this.ex().gp_page_labels_json(this.h, o));
|
|
1997
|
+
}
|
|
1998
|
+
/**
|
|
1999
|
+
* Replace the document's page labels. Pass an **empty** array to remove all
|
|
2000
|
+
* labels. Ranges are sorted by `startPage` and collapsed to one entry per page
|
|
2001
|
+
* (last wins). Returns `true` on success.
|
|
2002
|
+
*
|
|
2003
|
+
* @example
|
|
2004
|
+
* // Front matter in lowercase roman, body in decimal, appendix "A-1, A-2…".
|
|
2005
|
+
* doc.setPageLabels([
|
|
2006
|
+
* { startPage: 1, style: "romanLower", prefix: "", startNumber: 1 },
|
|
2007
|
+
* { startPage: 5, style: "decimal", prefix: "", startNumber: 1 },
|
|
2008
|
+
* { startPage: 20, style: "decimal", prefix: "A-", startNumber: 1 },
|
|
2009
|
+
* ]);
|
|
2010
|
+
*/
|
|
2011
|
+
setPageLabels(ranges) {
|
|
2012
|
+
const text = ranges.map(
|
|
2013
|
+
(r) => `${r.startPage} ${PAGE_LABEL_STYLE_TOKEN[r.style] ?? "-"} ${r.startNumber ?? 1} ${r.prefix ?? ""}`
|
|
2014
|
+
).join("\n");
|
|
2015
|
+
return this.g._withOptStr(text, (p, l) => this.ex().gp_set_page_labels(this.h, p, l)) === 0;
|
|
2016
|
+
}
|
|
2017
|
+
/**
|
|
2018
|
+
* The viewer-visible label string for the 1-based `page` (e.g. `"iv"`, `"A-3"`),
|
|
2019
|
+
* resolving the applicable `/PageLabels` range; the decimal page number when no
|
|
2020
|
+
* range applies (including a document with no page labels).
|
|
2021
|
+
*/
|
|
2022
|
+
pageLabel(page) {
|
|
2023
|
+
return this.g._str((o) => this.ex().gp_page_label(this.h, page, o));
|
|
2024
|
+
}
|
|
2025
|
+
/**
|
|
2026
|
+
* Author a presentation transition + auto-advance on `page` (1-based),
|
|
2027
|
+
* ISO 32000-1 §12.4.4. Writes the page's `/Trans` dictionary from
|
|
2028
|
+
* {@link PageTransition.style} plus only the optional sub-keys that apply to
|
|
2029
|
+
* that style (`dimension`/`motion` for `split`, `direction`/`scale`/
|
|
2030
|
+
* `flyAreaOpaque` for `fly`, …) — inapplicable fields are dropped.
|
|
2031
|
+
* {@link PageTransition.displayDuration} becomes the page's `/Dur`
|
|
2032
|
+
* (auto-advance); omitting it removes any existing `/Dur`. Re-calling replaces
|
|
2033
|
+
* the prior transition in full (idempotent). Returns `true` on success,
|
|
2034
|
+
* `false` for an unknown style, a negative/non-finite `duration`/`scale`/
|
|
2035
|
+
* `displayDuration`, or a bad page number.
|
|
2036
|
+
*
|
|
2037
|
+
* @example
|
|
2038
|
+
* // Kiosk slideshow: every page wipes in over 0.5 s, auto-advancing after 5 s.
|
|
2039
|
+
* for (let p = 1; p <= doc.pageCount(); p++) {
|
|
2040
|
+
* doc.setPageTransition(p, { style: "wipe", duration: 0.5, displayDuration: 5 });
|
|
2041
|
+
* }
|
|
2042
|
+
*/
|
|
2043
|
+
setPageTransition(page, trans) {
|
|
2044
|
+
const style = PAGE_TRANSITION_STYLES.indexOf(trans.style);
|
|
2045
|
+
if (style < 0) return false;
|
|
2046
|
+
const dimension = trans.dimension === "horizontal" ? 0 : trans.dimension === "vertical" ? 1 : -1;
|
|
2047
|
+
const motion = trans.motion === "inward" ? 0 : trans.motion === "outward" ? 1 : -1;
|
|
2048
|
+
const direction = trans.direction === void 0 ? -2 : trans.direction === "none" ? -1 : trans.direction;
|
|
2049
|
+
const flyB = trans.flyAreaOpaque === void 0 ? -1 : trans.flyAreaOpaque ? 1 : 0;
|
|
2050
|
+
return this.ex().gp_set_page_transition(
|
|
2051
|
+
this.h,
|
|
2052
|
+
page,
|
|
2053
|
+
style,
|
|
2054
|
+
trans.duration ?? Number.NaN,
|
|
2055
|
+
dimension,
|
|
2056
|
+
motion,
|
|
2057
|
+
direction,
|
|
2058
|
+
trans.scale ?? Number.NaN,
|
|
2059
|
+
flyB,
|
|
2060
|
+
trans.displayDuration ?? Number.NaN
|
|
2061
|
+
) === 0;
|
|
2062
|
+
}
|
|
2063
|
+
/**
|
|
2064
|
+
* The presentation transition declared on `page` (1-based), or `null` when the
|
|
2065
|
+
* page has no `/Trans` (ISO 32000-1 §12.4.4). Optional fields that do not apply
|
|
2066
|
+
* to the recovered style are omitted from the result.
|
|
2067
|
+
*/
|
|
2068
|
+
getPageTransition(page) {
|
|
2069
|
+
return this.g._jsonOrNull((o) => this.ex().gp_page_transition_json(this.h, page, o));
|
|
2070
|
+
}
|
|
2071
|
+
/**
|
|
2072
|
+
* Remove any presentation transition from `page` (1-based) — drops the page's
|
|
2073
|
+
* `/Trans` dictionary and its `/Dur` auto-advance entry. A no-op if neither is
|
|
2074
|
+
* present. Returns `true` on success.
|
|
2075
|
+
*/
|
|
2076
|
+
clearPageTransition(page) {
|
|
2077
|
+
return this.ex().gp_clear_page_transition(this.h, page) === 0;
|
|
2078
|
+
}
|
|
1441
2079
|
/**
|
|
1442
2080
|
* Bake a running header onto every in-range page (idempotent: re-baking
|
|
1443
2081
|
* replaces the prior header). Returns `true` on success.
|
|
@@ -1472,6 +2110,78 @@ var GigaPdfDoc = class {
|
|
|
1472
2110
|
(o) => this.ex().gp_header_footer(this.h, o)
|
|
1473
2111
|
);
|
|
1474
2112
|
}
|
|
2113
|
+
/**
|
|
2114
|
+
* Bake a **rich**, Word-like running header/footer from a {@link RunningHeaderFooter}
|
|
2115
|
+
* `def` (the source of truth — stored in the editor-meta sidecar, its visible
|
|
2116
|
+
* `/GPHF` band regenerated on every page). Text is set in an embedded font
|
|
2117
|
+
* (each item's `fontRef`, else the bundled OFL face — never base-14) and images
|
|
2118
|
+
* via the same path as {@link addImage}; both live inside the `/GPHF` span, so
|
|
2119
|
+
* they are excluded from {@link elements}/{@link textRuns} and masked by
|
|
2120
|
+
* {@link renderPageExcludingMarkedContent}. Idempotent (re-baking replaces the
|
|
2121
|
+
* prior band).
|
|
2122
|
+
*
|
|
2123
|
+
* `opts.date` is the bake date for `{{date}}` (the engine is clockless — pass
|
|
2124
|
+
* e.g. `new Date().toISOString().slice(0, 10)`); omit to fall back to the
|
|
2125
|
+
* document's `/Info` date. `opts.images` supplies the pixels each
|
|
2126
|
+
* `HFItem` of `type: "image"` references by `imageId` — an iterable of
|
|
2127
|
+
* `[imageId, bytes]` (a `Map<number, Uint8Array>` works directly); an image
|
|
2128
|
+
* whose id is absent is skipped. Returns `true` on success.
|
|
2129
|
+
*
|
|
2130
|
+
* @example
|
|
2131
|
+
* doc.setRunningHeaderFooter(
|
|
2132
|
+
* {
|
|
2133
|
+
* default: {
|
|
2134
|
+
* header: [{ type: "image", imageId: 1, w: 80, h: 24, anchor: "left" }],
|
|
2135
|
+
* footer: [{ type: "text", text: "{{title}} — {{page}}/{{pages}}", anchor: "center" }],
|
|
2136
|
+
* },
|
|
2137
|
+
* firstPage: { header: [], footer: [] }, // blank cover
|
|
2138
|
+
* differentFirstPage: true,
|
|
2139
|
+
* differentOddEven: true,
|
|
2140
|
+
* evenPage: { header: [{ type: "text", text: "{{page}}", anchor: "left" }], footer: [] },
|
|
2141
|
+
* oddPage: { header: [{ type: "text", text: "{{page}}", anchor: "right" }], footer: [] },
|
|
2142
|
+
* },
|
|
2143
|
+
* { date: new Date().toISOString().slice(0, 10), images: new Map([[1, logoPng]]) }
|
|
2144
|
+
* );
|
|
2145
|
+
*/
|
|
2146
|
+
setRunningHeaderFooter(def, opts) {
|
|
2147
|
+
const entries = opts?.images ? Array.from(opts.images) : [];
|
|
2148
|
+
let total = 4;
|
|
2149
|
+
for (const [, bytes] of entries) total += 8 + bytes.length;
|
|
2150
|
+
const blob = new Uint8Array(total);
|
|
2151
|
+
const dv = new DataView(blob.buffer);
|
|
2152
|
+
let off = 0;
|
|
2153
|
+
dv.setUint32(off, entries.length >>> 0, true);
|
|
2154
|
+
off += 4;
|
|
2155
|
+
for (const [id, bytes] of entries) {
|
|
2156
|
+
dv.setUint32(off, id >>> 0, true);
|
|
2157
|
+
off += 4;
|
|
2158
|
+
dv.setUint32(off, bytes.length >>> 0, true);
|
|
2159
|
+
off += 4;
|
|
2160
|
+
blob.set(bytes, off);
|
|
2161
|
+
off += bytes.length;
|
|
2162
|
+
}
|
|
2163
|
+
return this.g._withStr(
|
|
2164
|
+
JSON.stringify(def),
|
|
2165
|
+
(dp, dl) => this.g._withOptStr(
|
|
2166
|
+
opts?.date,
|
|
2167
|
+
(tp, tl) => this.g._withBytes(
|
|
2168
|
+
blob,
|
|
2169
|
+
(ip, il) => this.ex().gp_set_running_header_footer(this.h, dp, dl, tp, tl, ip, il)
|
|
2170
|
+
)
|
|
2171
|
+
)
|
|
2172
|
+
) === 0;
|
|
2173
|
+
}
|
|
2174
|
+
/**
|
|
2175
|
+
* The rich {@link RunningHeaderFooter} definition recorded by
|
|
2176
|
+
* {@link setRunningHeaderFooter} (read from the editor-meta sidecar — the
|
|
2177
|
+
* source of truth), or a minimal one reconstructed from a legacy flat
|
|
2178
|
+
* {@link setHeader}/{@link setFooter} bake, or `null` when neither is present.
|
|
2179
|
+
*/
|
|
2180
|
+
runningHeaderFooter() {
|
|
2181
|
+
return this.g._jsonOrNull(
|
|
2182
|
+
(o) => this.ex().gp_running_header_footer(this.h, o)
|
|
2183
|
+
);
|
|
2184
|
+
}
|
|
1475
2185
|
// render
|
|
1476
2186
|
renderPage(page, scale = 1) {
|
|
1477
2187
|
return this.g._buffer((o) => this.ex().gp_render_page(this.h, page, scale, o));
|
|
@@ -1508,6 +2218,33 @@ var GigaPdfDoc = class {
|
|
|
1508
2218
|
)
|
|
1509
2219
|
);
|
|
1510
2220
|
}
|
|
2221
|
+
/**
|
|
2222
|
+
* Rasterize a page to a PNG **excluding the ops inside a baked marked-content
|
|
2223
|
+
* span** named `marker` — and, when `skipText` is true, the page's text too — in
|
|
2224
|
+
* a **single** raster pass. For `marker = "GPHF"` (the default) this drops the
|
|
2225
|
+
* baked running header/footer band: the extraction views ({@link elements},
|
|
2226
|
+
* {@link textRuns}) already omit that band (it is never editable body content),
|
|
2227
|
+
* and this render omits it from the picture so it cannot double against an
|
|
2228
|
+
* editable overlay. With `skipText = true` it is the editor's text-free display
|
|
2229
|
+
* background minus the band; with `skipText = false`, the full page minus the
|
|
2230
|
+
* band. Like {@link renderPageNoText}, form-field widget appearances are omitted.
|
|
2231
|
+
*/
|
|
2232
|
+
renderPageExcludingMarkedContent(page, scale = 1, skipText = true, marker = "GPHF") {
|
|
2233
|
+
return this.g._buffer(
|
|
2234
|
+
(o) => this.g._withStr(
|
|
2235
|
+
marker,
|
|
2236
|
+
(p, l) => this.ex().gp_render_page_excluding_marked_content(
|
|
2237
|
+
this.h,
|
|
2238
|
+
page,
|
|
2239
|
+
scale,
|
|
2240
|
+
skipText ? 1 : 0,
|
|
2241
|
+
p,
|
|
2242
|
+
l,
|
|
2243
|
+
o
|
|
2244
|
+
)
|
|
2245
|
+
)
|
|
2246
|
+
);
|
|
2247
|
+
}
|
|
1511
2248
|
// fonts — embed a downloaded font, then add real selectable text
|
|
1512
2249
|
/**
|
|
1513
2250
|
* Embed an outline font program as a Type0 font and return its object number
|
|
@@ -1679,8 +2416,73 @@ var GigaPdfDoc = class {
|
|
|
1679
2416
|
toRtf() {
|
|
1680
2417
|
return this.g._buffer((o) => this.ex().gp_to_rtf(this.h, o));
|
|
1681
2418
|
}
|
|
1682
|
-
|
|
1683
|
-
|
|
2419
|
+
/**
|
|
2420
|
+
* Re-serialize the document as **PDF/A** (archival).
|
|
2421
|
+
*
|
|
2422
|
+
* `level` selects the conformance flavour (default `"pdfa-2b"`):
|
|
2423
|
+
* - `"pdfa-1b"` — ISO 19005-1, based on PDF 1.4.
|
|
2424
|
+
* - `"pdfa-1a"` — ISO 19005-1 **Tagged PDF** (level A): 1b + a logical
|
|
2425
|
+
* structure tree, marked content and `/Lang`. Built from the structure the
|
|
2426
|
+
* engine reconstructs (paragraphs, headings, tables, lists).
|
|
2427
|
+
* - `"pdfa-2b"` — ISO 19005-2 (default).
|
|
2428
|
+
* - `"pdfa-2u"` — like 2b but requires every glyph Unicode-mapped (a
|
|
2429
|
+
* `/ToUnicode` CMap on each font); only validator-clean when the source
|
|
2430
|
+
* fonts already carry one — otherwise prefer `"pdfa-2b"`.
|
|
2431
|
+
* - `"pdfa-2a"` — ISO 19005-2 **Tagged PDF** (level A): 2u + a logical
|
|
2432
|
+
* structure tree and marked content (`/StructTreeRoot`, `/MarkInfo`).
|
|
2433
|
+
* - `"pdfa-3b"` — ISO 19005-3; permits embedded file attachments.
|
|
2434
|
+
*
|
|
2435
|
+
* Full conformance also requires every font embedded — this method does not
|
|
2436
|
+
* embed missing fonts (see the Rust `to_pdfa_level` docs). For the level-A
|
|
2437
|
+
* (`1a`/`2a`) flavours the tagging is rendering-neutral: it only inserts
|
|
2438
|
+
* balanced marked-content operators and a structure tree, never changing the
|
|
2439
|
+
* page appearance.
|
|
2440
|
+
*/
|
|
2441
|
+
toPdfA(level = "pdfa-2b") {
|
|
2442
|
+
return this.g._withStr(
|
|
2443
|
+
level,
|
|
2444
|
+
(p, l) => this.g._buffer((o) => this.ex().gp_to_pdfa(this.h, p, l, o))
|
|
2445
|
+
);
|
|
2446
|
+
}
|
|
2447
|
+
/**
|
|
2448
|
+
* Author a **tagged (accessible) PDF** — a `/StructTreeRoot` logical-structure
|
|
2449
|
+
* tree (`P`/`H1`–`H6`/`Table`/`L`/`Figure` …) with marked content, `/MarkInfo`,
|
|
2450
|
+
* `/Lang`, `/RoleMap` and `/Alt` on figures — **without** forcing PDF/A. Pass
|
|
2451
|
+
* `{ pdfUa: true }` to also stamp the PDF/UA-1 identifier (ISO 14289). If the
|
|
2452
|
+
* document has no reconstructable structure the plain PDF is returned.
|
|
2453
|
+
* ISO 32000-1 §14.7/§14.8.
|
|
2454
|
+
*/
|
|
2455
|
+
toTagged(opts = {}) {
|
|
2456
|
+
return this.g._buffer((o) => this.ex().gp_to_tagged(this.h, opts.pdfUa ? 1 : 0, o));
|
|
2457
|
+
}
|
|
2458
|
+
/**
|
|
2459
|
+
* The number of taggable **figures** the engine reconstructs across the whole
|
|
2460
|
+
* document — the valid range `0..figureCount()` for {@link setFigureAlt}'s
|
|
2461
|
+
* `index`. Each figure is an image the geometric reconstruction surfaces; the
|
|
2462
|
+
* Tagged-PDF / PDF-A-level-A export emits one `/Figure` structure element per
|
|
2463
|
+
* figure, in this same order.
|
|
2464
|
+
*/
|
|
2465
|
+
figureCount() {
|
|
2466
|
+
return this.ex().gp_figure_count(this.h);
|
|
2467
|
+
}
|
|
2468
|
+
/**
|
|
2469
|
+
* Attach **author-supplied alternate text** (`/Alt`) to a figure so assistive
|
|
2470
|
+
* technology can describe the image (WCAG / PDF/UA, ISO 32000-1 §14.9.3).
|
|
2471
|
+
*
|
|
2472
|
+
* `index` is the **document-global figure index** — figures are numbered
|
|
2473
|
+
* `0, 1, 2, …` in page order, then in page-content order within each page (the
|
|
2474
|
+
* Nth image of the whole document is figure `N`; {@link figureCount} bounds the
|
|
2475
|
+
* range). The text lands on the matching `/Figure` structure element's `/Alt`
|
|
2476
|
+
* when an accessible export is produced — {@link toTagged} or {@link toPdfA}
|
|
2477
|
+
* with `"pdfa-1a"`/`"pdfa-2a"`. Figures with no author-supplied text keep a
|
|
2478
|
+
* generic non-empty placeholder, so the output stays structurally valid even
|
|
2479
|
+
* for unlabeled figures.
|
|
2480
|
+
*
|
|
2481
|
+
* Returns `true` on success; `false` if `alt` is empty (a `/Alt` must be
|
|
2482
|
+
* non-empty) or the call otherwise fails.
|
|
2483
|
+
*/
|
|
2484
|
+
setFigureAlt(index, alt) {
|
|
2485
|
+
return this.g._withStr(alt, (p, l) => this.ex().gp_set_figure_alt(this.h, index, p, l)) === 0;
|
|
1684
2486
|
}
|
|
1685
2487
|
// security
|
|
1686
2488
|
/**
|
|
@@ -1735,6 +2537,117 @@ var GigaPdfDoc = class {
|
|
|
1735
2537
|
)
|
|
1736
2538
|
);
|
|
1737
2539
|
}
|
|
2540
|
+
/**
|
|
2541
|
+
* Re-encrypt an already-opened (decrypted) document with **new** passwords,
|
|
2542
|
+
* discarding the prior encryption (ISO 32000-1 §7.6). Opening with the old
|
|
2543
|
+
* password is what authorises the change. Mirrors {@link saveEncrypted} plus
|
|
2544
|
+
* `encryptMetadata` (when `false`, the metadata stream is left in the clear).
|
|
2545
|
+
*/
|
|
2546
|
+
changePasswords(newPassword, fileId, opts = {}) {
|
|
2547
|
+
const algo = opts.algorithm ?? "aes256";
|
|
2548
|
+
const algoCode = algo === "rc4" ? 0 : algo === "aes128" ? 1 : 2;
|
|
2549
|
+
const permissions = opts.flags !== void 0 ? this.g.permissionsToP(opts.flags) : opts.permissions ?? this.g.permissionsToP();
|
|
2550
|
+
let key = opts.keySeed ?? new Uint8Array(0);
|
|
2551
|
+
if (algoCode === 2 && key.length < 32) {
|
|
2552
|
+
key = cryptoRandom(32);
|
|
2553
|
+
}
|
|
2554
|
+
const encMeta = opts.encryptMetadata ?? true;
|
|
2555
|
+
return this.g._withStr(
|
|
2556
|
+
newPassword,
|
|
2557
|
+
(pwP, pwL) => this.g._withOptStr(
|
|
2558
|
+
opts.ownerPassword,
|
|
2559
|
+
(oP, oL) => this.g._withStr(
|
|
2560
|
+
fileId,
|
|
2561
|
+
(idP, idL) => this.g._withBytes(
|
|
2562
|
+
key,
|
|
2563
|
+
(kP, kL) => this.g._buffer(
|
|
2564
|
+
(o) => this.ex().gp_change_passwords(
|
|
2565
|
+
this.h,
|
|
2566
|
+
pwP,
|
|
2567
|
+
pwL,
|
|
2568
|
+
oP,
|
|
2569
|
+
oL,
|
|
2570
|
+
idP,
|
|
2571
|
+
idL,
|
|
2572
|
+
kP,
|
|
2573
|
+
kL,
|
|
2574
|
+
algoCode,
|
|
2575
|
+
permissions,
|
|
2576
|
+
encMeta ? 1 : 0,
|
|
2577
|
+
o
|
|
2578
|
+
)
|
|
2579
|
+
)
|
|
2580
|
+
)
|
|
2581
|
+
)
|
|
2582
|
+
)
|
|
2583
|
+
);
|
|
2584
|
+
}
|
|
2585
|
+
/**
|
|
2586
|
+
* Strip encryption from an already-opened (decrypted) document, returning a
|
|
2587
|
+
* **plaintext** PDF. The document must have been opened with a valid password.
|
|
2588
|
+
*/
|
|
2589
|
+
removeEncryption() {
|
|
2590
|
+
return this.g._buffer((o) => this.ex().gp_remove_encryption(this.h, o));
|
|
2591
|
+
}
|
|
2592
|
+
/**
|
|
2593
|
+
* Encrypt the document to one or more **X.509 recipients** (public-key /
|
|
2594
|
+
* certificate security, ISO 32000-1 §7.6.5, `/Filter /Adobe.PubSec`): only a
|
|
2595
|
+
* holder of a recipient private key can open it — no shared password.
|
|
2596
|
+
* `certificates` are DER X.509 certs. `seed`/`rngSeed` default to Web Crypto
|
|
2597
|
+
* randomness. Open the result with {@link GigaPdfEngine.openWithPrivateKey}.
|
|
2598
|
+
*/
|
|
2599
|
+
encryptForRecipients(certificates, opts = {}) {
|
|
2600
|
+
if (certificates.length === 0) {
|
|
2601
|
+
throw new Error("encryptForRecipients needs at least one recipient certificate");
|
|
2602
|
+
}
|
|
2603
|
+
const total = certificates.reduce((n, c) => n + c.length, 0);
|
|
2604
|
+
const blob = new Uint8Array(total);
|
|
2605
|
+
const lens = [];
|
|
2606
|
+
let off = 0;
|
|
2607
|
+
for (const c of certificates) {
|
|
2608
|
+
blob.set(c, off);
|
|
2609
|
+
off += c.length;
|
|
2610
|
+
lens.push(c.length);
|
|
2611
|
+
}
|
|
2612
|
+
const permissions = opts.flags !== void 0 ? this.g.permissionsToP(opts.flags) : opts.permissions ?? this.g.permissionsToP();
|
|
2613
|
+
const aes256 = opts.aes256 ?? true;
|
|
2614
|
+
const encMeta = opts.encryptMetadata ?? true;
|
|
2615
|
+
const seed = opts.seed ?? cryptoRandom(20);
|
|
2616
|
+
const rng = opts.rngSeed ?? cryptoRandom(32);
|
|
2617
|
+
const out = this.g._withBytes(
|
|
2618
|
+
blob,
|
|
2619
|
+
(cP, cL) => this.g._withU32(
|
|
2620
|
+
lens,
|
|
2621
|
+
(lP, lC) => this.g._withBytes(
|
|
2622
|
+
seed,
|
|
2623
|
+
(sP, sL) => this.g._withBytes(
|
|
2624
|
+
rng,
|
|
2625
|
+
(rP, rL) => this.g._buffer(
|
|
2626
|
+
(o) => this.ex().gp_encrypt_for_recipients(
|
|
2627
|
+
this.h,
|
|
2628
|
+
cP,
|
|
2629
|
+
cL,
|
|
2630
|
+
lP,
|
|
2631
|
+
lC,
|
|
2632
|
+
permissions,
|
|
2633
|
+
aes256 ? 1 : 0,
|
|
2634
|
+
encMeta ? 1 : 0,
|
|
2635
|
+
sP,
|
|
2636
|
+
sL,
|
|
2637
|
+
rP,
|
|
2638
|
+
rL,
|
|
2639
|
+
o
|
|
2640
|
+
)
|
|
2641
|
+
)
|
|
2642
|
+
)
|
|
2643
|
+
)
|
|
2644
|
+
)
|
|
2645
|
+
);
|
|
2646
|
+
if (out.length === 0) {
|
|
2647
|
+
throw new Error("encryptForRecipients failed (invalid recipient certificate?)");
|
|
2648
|
+
}
|
|
2649
|
+
return out;
|
|
2650
|
+
}
|
|
1738
2651
|
/** Self-signed digital signature. `random` ≥ 256 bytes from crypto.getRandomValues. */
|
|
1739
2652
|
sign(fields, random, keyBits = 2048) {
|
|
1740
2653
|
const rPtr = this.g._toWasm(random);
|
|
@@ -1745,6 +2658,43 @@ var GigaPdfDoc = class {
|
|
|
1745
2658
|
this.g._free(rPtr, random.length);
|
|
1746
2659
|
return out;
|
|
1747
2660
|
}
|
|
2661
|
+
/**
|
|
2662
|
+
* **Certify** the document (DocMDP) — like {@link sign} but also declares which
|
|
2663
|
+
* later changes are allowed: `docmdpLevel` is `1` (no changes), `2` (form-fill
|
|
2664
|
+
* + sign) or `3` (also annotate). `fields` is the same tab-separated string as
|
|
2665
|
+
* {@link sign} (`name⇥reason⇥date⇥notBefore⇥notAfter`).
|
|
2666
|
+
*/
|
|
2667
|
+
certify(fields, random, docmdpLevel, keyBits = 2048) {
|
|
2668
|
+
const rPtr = this.g._toWasm(random);
|
|
2669
|
+
const out = this.g._withStr(
|
|
2670
|
+
fields,
|
|
2671
|
+
(fP, fL) => this.g._buffer(
|
|
2672
|
+
(o) => this.ex().gp_sign_certify(this.h, fP, fL, rPtr, random.length, keyBits, docmdpLevel, o)
|
|
2673
|
+
)
|
|
2674
|
+
);
|
|
2675
|
+
this.g._free(rPtr, random.length);
|
|
2676
|
+
return out;
|
|
2677
|
+
}
|
|
2678
|
+
/**
|
|
2679
|
+
* List every signature on the document (each `/Sig` field's `/V`) with its
|
|
2680
|
+
* metadata and `/ByteRange`. For cryptographic validity call
|
|
2681
|
+
* {@link verifySignatures}.
|
|
2682
|
+
*/
|
|
2683
|
+
signatures() {
|
|
2684
|
+
return this.g._json((o) => this.ex().gp_signatures_json(this.h, o));
|
|
2685
|
+
}
|
|
2686
|
+
/**
|
|
2687
|
+
* Cryptographically verify every signature against `pdf` — the **original
|
|
2688
|
+
* bytes** this document was opened from. Each report carries `byteRangeOk`,
|
|
2689
|
+
* `digestOk` (content integrity), `signatureOk` (the RSA signature),
|
|
2690
|
+
* `coversWholeDocument`, the signer CN, and the algorithm.
|
|
2691
|
+
*/
|
|
2692
|
+
verifySignatures(pdf) {
|
|
2693
|
+
return this.g._withBytes(
|
|
2694
|
+
pdf,
|
|
2695
|
+
(p, l) => this.g._json((o) => this.ex().gp_verify_signatures(this.h, p, l, o))
|
|
2696
|
+
);
|
|
2697
|
+
}
|
|
1748
2698
|
/**
|
|
1749
2699
|
* Sign with a PKCS#12 (`.p12`/`.pfx`) identity — a CA-issued / eIDAS
|
|
1750
2700
|
* certificate and its RSA key, imported natively (no external crypto). `opts`
|
|
@@ -2012,13 +2962,49 @@ var GigaPdfDoc = class {
|
|
|
2012
2962
|
(p, l) => this.g._str((o) => this.ex().gp_get_metadata(this.h, p, l, o))
|
|
2013
2963
|
);
|
|
2014
2964
|
}
|
|
2015
|
-
/**
|
|
2965
|
+
/**
|
|
2966
|
+
* Set a **single** Info-dictionary entry (e.g. `"Title"`, `"Author"`). This
|
|
2967
|
+
* touches only `/Info`; use {@link setInfo} to update the typed fields and keep
|
|
2968
|
+
* the XMP `/Metadata` packet in sync.
|
|
2969
|
+
*/
|
|
2016
2970
|
setMetadata(key, value) {
|
|
2017
2971
|
return this.g._withStr(
|
|
2018
2972
|
key,
|
|
2019
2973
|
(kP, kL) => this.g._withStr(value, (vP, vL) => this.ex().gp_set_metadata(this.h, kP, kL, vP, vL))
|
|
2020
2974
|
) === 0;
|
|
2021
2975
|
}
|
|
2976
|
+
/**
|
|
2977
|
+
* The document's XMP metadata packet (catalog `/Metadata`, ISO 32000-1 §14.3.2)
|
|
2978
|
+
* as raw bytes, or `null` when the document carries no XMP.
|
|
2979
|
+
*/
|
|
2980
|
+
getXmp() {
|
|
2981
|
+
const bytes = this.g._buffer((o) => this.ex().gp_get_xmp(this.h, o));
|
|
2982
|
+
return bytes.length === 0 ? null : bytes;
|
|
2983
|
+
}
|
|
2984
|
+
/**
|
|
2985
|
+
* Replace (or create) the document's XMP metadata stream (catalog `/Metadata`,
|
|
2986
|
+
* stored uncompressed). Accepts a UTF-8 string or raw bytes. Returns `true` on
|
|
2987
|
+
* success.
|
|
2988
|
+
*/
|
|
2989
|
+
setXmp(xmp) {
|
|
2990
|
+
const bytes = typeof xmp === "string" ? new TextEncoder().encode(xmp) : xmp;
|
|
2991
|
+
return this.g._withBytes(bytes, (p, l) => this.ex().gp_set_xmp(this.h, p, l)) === 0;
|
|
2992
|
+
}
|
|
2993
|
+
/**
|
|
2994
|
+
* Set the standard document-information fields, writing **both** the `/Info`
|
|
2995
|
+
* dictionary and a synced XMP `/Metadata` packet so the two never drift. This is
|
|
2996
|
+
* a **partial** update — only the fields you provide are changed; omit a field
|
|
2997
|
+
* to leave it untouched. Returns `true` on success.
|
|
2998
|
+
*
|
|
2999
|
+
* @example
|
|
3000
|
+
* doc.setInfo({ title: "Annual Report", author: "Ada Lovelace", keywords: "finance, 2026" });
|
|
3001
|
+
*/
|
|
3002
|
+
setInfo(fields) {
|
|
3003
|
+
return this.g._withStr(
|
|
3004
|
+
JSON.stringify(fields),
|
|
3005
|
+
(p, l) => this.ex().gp_set_info_json(this.h, p, l)
|
|
3006
|
+
) === 0;
|
|
3007
|
+
}
|
|
2022
3008
|
// annotations (Acrobat-style markup)
|
|
2023
3009
|
annotations(page) {
|
|
2024
3010
|
return this.g._json((o) => this.ex().gp_annotations_json(this.h, page, o));
|
|
@@ -2133,6 +3119,73 @@ var GigaPdfDoc = class {
|
|
|
2133
3119
|
(p, l) => this.ex().gp_add_stamp(this.h, page, x0, y0, x1, y1, p, l, RGB(rgb))
|
|
2134
3120
|
) === 0;
|
|
2135
3121
|
}
|
|
3122
|
+
/**
|
|
3123
|
+
* Add a `/Circle` (ellipse) annotation inscribed in `[x0,y0,x1,y1]`. `stroke`
|
|
3124
|
+
* (border) and `fill` (interior) are packed `0xRRGGBB` numbers, or `null` to
|
|
3125
|
+
* omit. Returns `true` on success.
|
|
3126
|
+
*/
|
|
3127
|
+
addCircleAnnotation(page, x0, y0, x1, y1, stroke = 0, fill = null, lineWidth = 1) {
|
|
3128
|
+
return this.ex().gp_add_circle_annot(
|
|
3129
|
+
this.h,
|
|
3130
|
+
page,
|
|
3131
|
+
x0,
|
|
3132
|
+
y0,
|
|
3133
|
+
x1,
|
|
3134
|
+
y1,
|
|
3135
|
+
RGB(stroke ?? 0),
|
|
3136
|
+
stroke === null ? 0 : 1,
|
|
3137
|
+
RGB(fill ?? 0),
|
|
3138
|
+
fill === null ? 0 : 1,
|
|
3139
|
+
lineWidth
|
|
3140
|
+
) === 0;
|
|
3141
|
+
}
|
|
3142
|
+
/**
|
|
3143
|
+
* Add a `/Polygon` annotation — a closed shape through `points` (a flat
|
|
3144
|
+
* `[x0, y0, x1, y1, …]` array, PDF user space), with optional `stroke`/`fill`
|
|
3145
|
+
* (`0xRRGGBB` or `null`). Returns `true` on success.
|
|
3146
|
+
*/
|
|
3147
|
+
addPolygonAnnotation(page, points, stroke = 0, fill = null, lineWidth = 1) {
|
|
3148
|
+
return this.g._withF64(
|
|
3149
|
+
points,
|
|
3150
|
+
(p, c) => this.ex().gp_add_polygon_annot(
|
|
3151
|
+
this.h,
|
|
3152
|
+
page,
|
|
3153
|
+
p,
|
|
3154
|
+
c,
|
|
3155
|
+
RGB(stroke ?? 0),
|
|
3156
|
+
stroke === null ? 0 : 1,
|
|
3157
|
+
RGB(fill ?? 0),
|
|
3158
|
+
fill === null ? 0 : 1,
|
|
3159
|
+
lineWidth
|
|
3160
|
+
)
|
|
3161
|
+
) === 0;
|
|
3162
|
+
}
|
|
3163
|
+
/**
|
|
3164
|
+
* Add a `/PolyLine` annotation — an open path through `points` (a flat
|
|
3165
|
+
* `[x0, y0, x1, y1, …]` array). `rgb` is packed `0xRRGGBB`.
|
|
3166
|
+
*/
|
|
3167
|
+
addPolylineAnnotation(page, points, rgb = 0, lineWidth = 1) {
|
|
3168
|
+
return this.g._withF64(
|
|
3169
|
+
points,
|
|
3170
|
+
(p, c) => this.ex().gp_add_polyline_annot(this.h, page, p, c, RGB(rgb), lineWidth)
|
|
3171
|
+
) === 0;
|
|
3172
|
+
}
|
|
3173
|
+
/**
|
|
3174
|
+
* Add a `/Caret` annotation — a small upward wedge in `[x0,y0,x1,y1]` marking
|
|
3175
|
+
* an insertion point. `rgb` is packed `0xRRGGBB`.
|
|
3176
|
+
*/
|
|
3177
|
+
addCaretAnnotation(page, x0, y0, x1, y1, rgb = 0) {
|
|
3178
|
+
return this.ex().gp_add_caret_annot(this.h, page, x0, y0, x1, y1, RGB(rgb)) === 0;
|
|
3179
|
+
}
|
|
3180
|
+
/**
|
|
3181
|
+
* Regenerate the appearance stream (`/AP /N`) of the 0-based `index`
|
|
3182
|
+
* annotation on `page` from its stored geometry, after editing its colour,
|
|
3183
|
+
* border or geometry. Returns `true` on success, `false` for a bad index or a
|
|
3184
|
+
* subtype whose appearance can't be reconstructed (FreeText/Stamp/Text/Link).
|
|
3185
|
+
*/
|
|
3186
|
+
regenerateAppearance(page, index) {
|
|
3187
|
+
return this.ex().gp_regenerate_appearance(this.h, page, index) === 0;
|
|
3188
|
+
}
|
|
2136
3189
|
flattenAnnotations(page) {
|
|
2137
3190
|
return this.ex().gp_flatten_annotations(this.h, page);
|
|
2138
3191
|
}
|
|
@@ -2201,6 +3254,150 @@ var GigaPdfDoc = class {
|
|
|
2201
3254
|
data: this.g._fromBase64(dataBase64)
|
|
2202
3255
|
}));
|
|
2203
3256
|
}
|
|
3257
|
+
/**
|
|
3258
|
+
* Embed `bytes` as a document-level file attachment named `name`
|
|
3259
|
+
* (`/Names /EmbeddedFiles`, ISO 32000-1 §7.11.4). Re-using a `name` **replaces**
|
|
3260
|
+
* that attachment; the bytes are stored FlateDecode-compressed. Returns `true`
|
|
3261
|
+
* on success (`false` e.g. for an empty name).
|
|
3262
|
+
*/
|
|
3263
|
+
addAttachment(name, bytes, opts = {}) {
|
|
3264
|
+
return this.g._withStr(
|
|
3265
|
+
name,
|
|
3266
|
+
(np, nl) => this.g._withBytes(
|
|
3267
|
+
bytes,
|
|
3268
|
+
(bp, bl) => this.g._withOptStr(
|
|
3269
|
+
opts.mime ?? "",
|
|
3270
|
+
(mp, ml) => this.g._withOptStr(
|
|
3271
|
+
opts.description ?? "",
|
|
3272
|
+
(dp, dl) => this.ex().gp_add_attachment(this.h, np, nl, bp, bl, mp, ml, dp, dl)
|
|
3273
|
+
)
|
|
3274
|
+
)
|
|
3275
|
+
)
|
|
3276
|
+
) === 0;
|
|
3277
|
+
}
|
|
3278
|
+
/**
|
|
3279
|
+
* Embed `bytes` as an **associated file** (`/AF`, PDF/A-3) named `name` with the
|
|
3280
|
+
* given {@link AfRelationship} — the mechanism Factur-X / ZUGFeRD / Order-X use
|
|
3281
|
+
* to carry their invoice XML (`"alternative"`). The file is also a normal
|
|
3282
|
+
* attachment, is linked from the catalog `/AF` array, and its filespec carries
|
|
3283
|
+
* `/AFRelationship`. Returns `true` on success.
|
|
3284
|
+
*/
|
|
3285
|
+
addAssociatedFile(name, bytes, relationship, opts = {}) {
|
|
3286
|
+
const rel = AF_RELATIONSHIP_CODE[relationship] ?? AF_RELATIONSHIP_CODE.unspecified;
|
|
3287
|
+
return this.g._withStr(
|
|
3288
|
+
name,
|
|
3289
|
+
(np, nl) => this.g._withBytes(
|
|
3290
|
+
bytes,
|
|
3291
|
+
(bp, bl) => this.g._withOptStr(
|
|
3292
|
+
opts.mime ?? "",
|
|
3293
|
+
(mp, ml) => this.g._withOptStr(
|
|
3294
|
+
opts.description ?? "",
|
|
3295
|
+
(dp, dl) => this.ex().gp_add_associated_file(this.h, np, nl, bp, bl, mp, ml, dp, dl, rel)
|
|
3296
|
+
)
|
|
3297
|
+
)
|
|
3298
|
+
)
|
|
3299
|
+
) === 0;
|
|
3300
|
+
}
|
|
3301
|
+
/**
|
|
3302
|
+
* Remove the attachment named `name` (from `/Names /EmbeddedFiles` and, if
|
|
3303
|
+
* present, the catalog `/AF` array). Returns `true` if one was removed, `false`
|
|
3304
|
+
* if no attachment had that name.
|
|
3305
|
+
*/
|
|
3306
|
+
removeAttachment(name) {
|
|
3307
|
+
return this.g._withStr(name, (p, l) => this.ex().gp_remove_attachment(this.h, p, l)) === 1;
|
|
3308
|
+
}
|
|
3309
|
+
/**
|
|
3310
|
+
* Mark this document as an embedded-file **portfolio** and configure how its
|
|
3311
|
+
* attachments are presented, by writing the catalog `/Collection`
|
|
3312
|
+
* (ISO 32000-1 §7.11.6, §12.3.5). The files must already be embedded (add them
|
|
3313
|
+
* first with {@link addAttachment} / {@link addAssociatedFile}); this only adds
|
|
3314
|
+
* the presentation layer: the initial {@link CollectionConfig.view view}, the
|
|
3315
|
+
* {@link CollectionConfig.schema schema} columns, the
|
|
3316
|
+
* {@link CollectionConfig.sort sort} order, the
|
|
3317
|
+
* {@link CollectionConfig.defaultFile default file}, and per-file
|
|
3318
|
+
* {@link CollectionConfig.items column values} (each written as a `/CI` on the
|
|
3319
|
+
* matching file's filespec). An empty/omitted schema still produces a valid
|
|
3320
|
+
* `/Collection`. Calling again **replaces** the previous configuration. Returns
|
|
3321
|
+
* `true` on success (`false` on a malformed config or write error).
|
|
3322
|
+
*/
|
|
3323
|
+
setCollection(config) {
|
|
3324
|
+
return this.g._withStr(
|
|
3325
|
+
JSON.stringify(config),
|
|
3326
|
+
(p, l) => this.ex().gp_set_collection_json(this.h, p, l)
|
|
3327
|
+
) === 0;
|
|
3328
|
+
}
|
|
3329
|
+
/**
|
|
3330
|
+
* Read this document's portfolio configuration back from the catalog
|
|
3331
|
+
* `/Collection` — the reader counterpart of {@link setCollection}. Returns
|
|
3332
|
+
* `null` when the document is not a portfolio. The recovered
|
|
3333
|
+
* {@link CollectionConfig} carries the `view`, the `schema` columns (sorted by
|
|
3334
|
+
* order), the `sort`, the `defaultFile`, and each embedded file's `/CI` column
|
|
3335
|
+
* `values`.
|
|
3336
|
+
*/
|
|
3337
|
+
collection() {
|
|
3338
|
+
return this.g._json((o) => this.ex().gp_collection_json(this.h, o));
|
|
3339
|
+
}
|
|
3340
|
+
/**
|
|
3341
|
+
* Install a **document-level JavaScript** under the catalog `/Names /JavaScript`
|
|
3342
|
+
* name tree (ISO 32000-1 §7.7.3.4 + §12.6.4.16): a named JavaScript action
|
|
3343
|
+
* (`<< /S /JavaScript /JS … >>`) keyed by `name`. On open, a conforming viewer
|
|
3344
|
+
* runs every document-level script in **name (lexical) order** — this is where
|
|
3345
|
+
* form-calculation / validation helper libraries live (e.g. `AFNumber_Format`).
|
|
3346
|
+
* Re-using a `name` **replaces** that script; long sources are stored as a
|
|
3347
|
+
* FlateDecode stream, and sibling `/Names` subtrees (`/EmbeddedFiles`,
|
|
3348
|
+
* `/Dests`, …) are preserved. Returns `true` on success (`false` e.g. for an
|
|
3349
|
+
* empty name).
|
|
3350
|
+
*/
|
|
3351
|
+
addDocumentJavascript(name, script) {
|
|
3352
|
+
return this.g._withStr(
|
|
3353
|
+
name,
|
|
3354
|
+
(np, nl) => this.g._withStr(
|
|
3355
|
+
script,
|
|
3356
|
+
(sp, sl) => this.ex().gp_add_document_javascript(this.h, np, nl, sp, sl)
|
|
3357
|
+
)
|
|
3358
|
+
) === 0;
|
|
3359
|
+
}
|
|
3360
|
+
/**
|
|
3361
|
+
* Every document-level JavaScript as `{ name, script }` pairs, in name
|
|
3362
|
+
* (lexical) order — the read side of {@link addDocumentJavascript} (decodes
|
|
3363
|
+
* both a literal `/JS` string and a `/JS` stream).
|
|
3364
|
+
*/
|
|
3365
|
+
documentJavascripts() {
|
|
3366
|
+
return this.g._json((o) => this.ex().gp_document_javascripts_json(this.h, o));
|
|
3367
|
+
}
|
|
3368
|
+
/**
|
|
3369
|
+
* Remove the document-level JavaScript named `name` from `/Names /JavaScript`.
|
|
3370
|
+
* Returns `true` if one was removed, `false` if none had that name.
|
|
3371
|
+
*/
|
|
3372
|
+
removeDocumentJavascript(name) {
|
|
3373
|
+
return this.g._withStr(name, (p, l) => this.ex().gp_remove_document_javascript(this.h, p, l)) === 1;
|
|
3374
|
+
}
|
|
3375
|
+
/**
|
|
3376
|
+
* Add a page-anchored **FileAttachment** annotation over `rect` on the 1-based
|
|
3377
|
+
* `page`, pointing at the already-embedded attachment `name` (add it first with
|
|
3378
|
+
* {@link addAttachment}). `icon` is the visual marker (default `"PushPin"`).
|
|
3379
|
+
* Returns `true` on success (`false` if no such attachment exists).
|
|
3380
|
+
*/
|
|
3381
|
+
addFileAttachmentAnnot(page, rect, name, icon = "PushPin") {
|
|
3382
|
+
return this.g._withStr(
|
|
3383
|
+
name,
|
|
3384
|
+
(np, nl) => this.g._withOptStr(
|
|
3385
|
+
icon,
|
|
3386
|
+
(ip, il) => this.ex().gp_add_file_attachment_annot(
|
|
3387
|
+
this.h,
|
|
3388
|
+
page,
|
|
3389
|
+
rect.x,
|
|
3390
|
+
rect.y,
|
|
3391
|
+
rect.x + rect.w,
|
|
3392
|
+
rect.y + rect.h,
|
|
3393
|
+
np,
|
|
3394
|
+
nl,
|
|
3395
|
+
ip,
|
|
3396
|
+
il
|
|
3397
|
+
)
|
|
3398
|
+
)
|
|
3399
|
+
) === 0;
|
|
3400
|
+
}
|
|
2204
3401
|
/**
|
|
2205
3402
|
* Add an internal hyperlink over a rectangle that jumps to the named
|
|
2206
3403
|
* destination `name` (define it with {@link addNamedDest}). Unlike
|
|
@@ -2230,6 +3427,24 @@ var GigaPdfDoc = class {
|
|
|
2230
3427
|
removeLayer(id) {
|
|
2231
3428
|
return this.ex().gp_remove_layer(this.h, id) === 0;
|
|
2232
3429
|
}
|
|
3430
|
+
/**
|
|
3431
|
+
* Begin an optional-content marked-content sequence on `page` for the layer
|
|
3432
|
+
* `ocg` (its id, from {@link addLayer}). Registers the OCG under the page's
|
|
3433
|
+
* `/Resources /Properties` and appends `/OC /OCn BDC` to the content stream;
|
|
3434
|
+
* every drawing call after it ({@link addText}, {@link addRectangle},
|
|
3435
|
+
* {@link addImage}, …) is gated on that layer's visibility until the matching
|
|
3436
|
+
* {@link endOptionalContent} appends `EMC`. Calls nest. Returns the `OCn`
|
|
3437
|
+
* property name (empty string on error).
|
|
3438
|
+
*/
|
|
3439
|
+
beginOptionalContent(page, ocg) {
|
|
3440
|
+
return this.g._str(
|
|
3441
|
+
(o) => this.ex().gp_begin_optional_content(this.h, page, ocg, o)
|
|
3442
|
+
);
|
|
3443
|
+
}
|
|
3444
|
+
/** End the innermost optional-content sequence on `page` (`EMC`). */
|
|
3445
|
+
endOptionalContent(page) {
|
|
3446
|
+
return this.ex().gp_end_optional_content(this.h, page) === 0;
|
|
3447
|
+
}
|
|
2233
3448
|
// outline (bookmarks)
|
|
2234
3449
|
outline() {
|
|
2235
3450
|
return this.g._json((o) => this.ex().gp_outline_json(this.h, o));
|
|
@@ -2239,6 +3454,79 @@ var GigaPdfDoc = class {
|
|
|
2239
3454
|
const text = entries.map((e) => `${e.level} ${e.page ?? 0} ${e.title}`).join("\n");
|
|
2240
3455
|
return this.g._withStr(text, (p, l) => this.ex().gp_set_outline(this.h, p, l)) === 0;
|
|
2241
3456
|
}
|
|
3457
|
+
/**
|
|
3458
|
+
* Add a `/Link` annotation over `rect` (`{ x, y, w, h }`) carrying any
|
|
3459
|
+
* {@link Action} — the full action & destination model (GoTo with every fit
|
|
3460
|
+
* mode, GoToR, URI, Named navigation, Launch, JavaScript, SubmitForm,
|
|
3461
|
+
* ResetForm). Returns `true` on success (`false` for a malformed action).
|
|
3462
|
+
*
|
|
3463
|
+
* @example
|
|
3464
|
+
* doc.addLink(1, { x: 72, y: 700, w: 120, h: 16 },
|
|
3465
|
+
* { type: "goto", dest: { fit: "xyz", page: 4, top: 720, zoom: 1.5 } });
|
|
3466
|
+
*/
|
|
3467
|
+
addLink(page, rect, action) {
|
|
3468
|
+
return this.g._withStr(
|
|
3469
|
+
JSON.stringify(action),
|
|
3470
|
+
(p, l) => this.ex().gp_add_link(this.h, page, rect.x, rect.y, rect.x + rect.w, rect.y + rect.h, p, l)
|
|
3471
|
+
) === 0;
|
|
3472
|
+
}
|
|
3473
|
+
/**
|
|
3474
|
+
* Set the document `/OpenAction` — the {@link Action} performed when the file
|
|
3475
|
+
* is opened. Returns `true` on success.
|
|
3476
|
+
*/
|
|
3477
|
+
setOpenAction(action) {
|
|
3478
|
+
return this.g._withStr(
|
|
3479
|
+
JSON.stringify(action),
|
|
3480
|
+
(p, l) => this.ex().gp_set_open_action(this.h, p, l)
|
|
3481
|
+
) === 0;
|
|
3482
|
+
}
|
|
3483
|
+
/**
|
|
3484
|
+
* Remove the `linkIndex`-th `/Link` annotation on `page` (links counted in
|
|
3485
|
+
* order, ignoring non-link annotations). Returns `true` if one was removed.
|
|
3486
|
+
*/
|
|
3487
|
+
removeLink(page, linkIndex) {
|
|
3488
|
+
return this.ex().gp_remove_link(this.h, page, linkIndex) === 1;
|
|
3489
|
+
}
|
|
3490
|
+
/**
|
|
3491
|
+
* Replace the outline with {@link Bookmark}s that may carry actions (a `goto`
|
|
3492
|
+
* action becomes a `/Dest`, any other action an `/A`). An empty array clears
|
|
3493
|
+
* the outline. Returns `true` on success.
|
|
3494
|
+
*/
|
|
3495
|
+
setBookmarks(bookmarks) {
|
|
3496
|
+
const text = bookmarks.map((b) => `${b.level} ${b.title} ${b.action ? JSON.stringify(b.action) : ""}`).join("\n");
|
|
3497
|
+
return this.g._withOptStr(text, (p, l) => this.ex().gp_set_bookmarks(this.h, p, l)) === 0;
|
|
3498
|
+
}
|
|
3499
|
+
// catalog reading / UX hints (ViewerPreferences, PageLayout, PageMode)
|
|
3500
|
+
/**
|
|
3501
|
+
* Write the catalog `/ViewerPreferences` (ISO 32000-1 §12.2). Each omitted
|
|
3502
|
+
* field is left unchanged; a boolean sets the key. After applying, an empty
|
|
3503
|
+
* dictionary is removed. Returns `false` on an invalid `direction`.
|
|
3504
|
+
*/
|
|
3505
|
+
setViewerPreferences(prefs) {
|
|
3506
|
+
const tri = (v) => v === void 0 ? -1 : v ? 1 : 0;
|
|
3507
|
+
return this.g._withStr(
|
|
3508
|
+
prefs.direction ?? "",
|
|
3509
|
+
(dP, dL) => this.ex().gp_set_viewer_preferences(
|
|
3510
|
+
this.h,
|
|
3511
|
+
tri(prefs.hideToolbar),
|
|
3512
|
+
tri(prefs.hideMenubar),
|
|
3513
|
+
tri(prefs.hideWindowUI),
|
|
3514
|
+
tri(prefs.fitWindow),
|
|
3515
|
+
tri(prefs.centerWindow),
|
|
3516
|
+
tri(prefs.displayDocTitle),
|
|
3517
|
+
dP,
|
|
3518
|
+
dL
|
|
3519
|
+
)
|
|
3520
|
+
) === 0;
|
|
3521
|
+
}
|
|
3522
|
+
/** Set the catalog `/PageLayout`. `null` removes the key. Returns `false` on an unknown name. */
|
|
3523
|
+
setPageLayout(layout) {
|
|
3524
|
+
return this.g._withStr(layout ?? "", (p, l) => this.ex().gp_set_page_layout(this.h, p, l)) === 0;
|
|
3525
|
+
}
|
|
3526
|
+
/** Set the catalog `/PageMode`. `null` removes the key. Returns `false` on an unknown name. */
|
|
3527
|
+
setPageMode(mode) {
|
|
3528
|
+
return this.g._withStr(mode ?? "", (p, l) => this.ex().gp_set_page_mode(this.h, p, l)) === 0;
|
|
3529
|
+
}
|
|
2242
3530
|
// interactive forms (AcroForm)
|
|
2243
3531
|
fields() {
|
|
2244
3532
|
return this.g._json((o) => this.ex().gp_fields_json(this.h, o));
|
|
@@ -2400,10 +3688,79 @@ var GigaPdfDoc = class {
|
|
|
2400
3688
|
)
|
|
2401
3689
|
) === 0;
|
|
2402
3690
|
}
|
|
3691
|
+
/**
|
|
3692
|
+
* Create a **visible signature field** (`/FT /Sig`) over `rect` — an empty
|
|
3693
|
+
* widget the signing pipeline can later target — and flag the AcroForm
|
|
3694
|
+
* `/SigFlags`. Returns `true` on success.
|
|
3695
|
+
*/
|
|
3696
|
+
addSignatureField(page, name, rect, opts = {}) {
|
|
3697
|
+
const st = styleArgs(opts.style);
|
|
3698
|
+
return this.g._withStr(
|
|
3699
|
+
name,
|
|
3700
|
+
(nP, nL) => this.ex().gp_add_signature_field(
|
|
3701
|
+
this.h,
|
|
3702
|
+
page,
|
|
3703
|
+
nP,
|
|
3704
|
+
nL,
|
|
3705
|
+
rect[0],
|
|
3706
|
+
rect[1],
|
|
3707
|
+
rect[2],
|
|
3708
|
+
rect[3],
|
|
3709
|
+
...st
|
|
3710
|
+
)
|
|
3711
|
+
) === 0;
|
|
3712
|
+
}
|
|
3713
|
+
/**
|
|
3714
|
+
* Attach field-level JavaScript to a field's `/AA` for the given `trigger`
|
|
3715
|
+
* (`"keystroke"` filters input, `"format"` formats display, `"validate"`
|
|
3716
|
+
* checks on change, `"calculate"` recomputes — ordered by
|
|
3717
|
+
* {@link setCalculationOrder}). Returns `true` if set, `false` if no field has
|
|
3718
|
+
* that name.
|
|
3719
|
+
*/
|
|
3720
|
+
setFieldScript(name, trigger, js) {
|
|
3721
|
+
return this.g._withStr(
|
|
3722
|
+
name,
|
|
3723
|
+
(nP, nL) => this.g._withStr(
|
|
3724
|
+
trigger,
|
|
3725
|
+
(tP, tL) => this.g._withStr(
|
|
3726
|
+
js,
|
|
3727
|
+
(jP, jL) => this.ex().gp_set_field_script(this.h, nP, nL, tP, tL, jP, jL)
|
|
3728
|
+
)
|
|
3729
|
+
)
|
|
3730
|
+
) === 1;
|
|
3731
|
+
}
|
|
3732
|
+
/**
|
|
3733
|
+
* Set the AcroForm calculation order (`/CO`) — the sequence in which fields
|
|
3734
|
+
* with a `calculate` script recompute. Unknown names are skipped.
|
|
3735
|
+
*/
|
|
3736
|
+
setCalculationOrder(names) {
|
|
3737
|
+
return this.g._withOptStr(
|
|
3738
|
+
names.join("\n"),
|
|
3739
|
+
(p, l) => this.ex().gp_set_calculation_order(this.h, p, l)
|
|
3740
|
+
) === 0;
|
|
3741
|
+
}
|
|
3742
|
+
/**
|
|
3743
|
+
* Delete a form field by name (removed from `/Fields`, `/CO` and every page's
|
|
3744
|
+
* annotations). Returns `true` if a field was removed.
|
|
3745
|
+
*/
|
|
3746
|
+
removeField(name) {
|
|
3747
|
+
return this.g._withStr(name, (p, l) => this.ex().gp_remove_field(this.h, p, l)) === 1;
|
|
3748
|
+
}
|
|
3749
|
+
/**
|
|
3750
|
+
* Rebuild a field's appearance from its current value/style — call after
|
|
3751
|
+
* changing a field's value programmatically. Returns `true` if regenerated
|
|
3752
|
+
* (`false` for an unknown name or a kind that can't be regenerated alone, e.g.
|
|
3753
|
+
* a radio parent with kids).
|
|
3754
|
+
*/
|
|
3755
|
+
regenerateFieldAppearance(name) {
|
|
3756
|
+
return this.g._withStr(name, (p, l) => this.ex().gp_regenerate_field_appearance(this.h, p, l)) === 1;
|
|
3757
|
+
}
|
|
2403
3758
|
};
|
|
2404
3759
|
export {
|
|
2405
3760
|
GigaPdfDoc,
|
|
2406
3761
|
GigaPdfEngine,
|
|
3762
|
+
PAGE_BOX_KINDS,
|
|
3763
|
+
PAGE_TRANSITION_STYLES,
|
|
2407
3764
|
defaultCrlGet,
|
|
2408
3765
|
defaultOcspPost,
|
|
2409
3766
|
defaultTsaPost
|