@qrcommunication/gigapdf-lib 0.52.2 → 0.52.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1014,6 +1014,34 @@ declare class GigaPdfDoc {
1014
1014
  addSvg(page: number, svg: string, x: number, y: number, w: number, h: number): boolean;
1015
1015
  /** True redaction: delete content intersecting the region (no opaque cover by default). */
1016
1016
  redact(page: number, x: number, y: number, w: number, h: number, coverRgb?: number, hasCover?: boolean): number;
1017
+ /**
1018
+ * True **PII redaction** of one or more rectangles `(x, y, width, height)` in
1019
+ * PDF points (origin bottom-left), in a single call. For every rect this:
1020
+ *
1021
+ * - **deletes** the overlapping text/vector elements from the content stream —
1022
+ * the glyphs and their `/ToUnicode` mapping are gone, so copy/paste and text
1023
+ * extraction reveal nothing in the area;
1024
+ * - **overwrites the pixels** of any underlying image (a scan/photo) with opaque
1025
+ * black — only the intersecting sub-rectangle, so the rest of the page image
1026
+ * survives — and re-encodes the image, erasing the sensitive pixels from the
1027
+ * bytes (not merely covering them);
1028
+ * - strips overlapping annotations and clears their form-field values;
1029
+ * - paints an opaque **black** box over the rect as the visible redaction mark.
1030
+ *
1031
+ * The black cover is the default for PII (unlike {@link redact}). Pass
1032
+ * `opts.coverRgb` to change the mark colour, or `opts.cover = false` to remove
1033
+ * the content/pixels with no visible box. Returns the number of content
1034
+ * elements deleted across all rects.
1035
+ */
1036
+ redactPii(page: number, rects: {
1037
+ x: number;
1038
+ y: number;
1039
+ width: number;
1040
+ height: number;
1041
+ }[], opts?: {
1042
+ cover?: boolean;
1043
+ coverRgb?: number;
1044
+ }): number;
1017
1045
  rotatePage(page: number, degrees: number): boolean;
1018
1046
  deletePage(page: number): boolean;
1019
1047
  movePage(from: number, to: number): boolean;
@@ -1094,8 +1122,16 @@ declare class GigaPdfDoc {
1094
1122
  * font's char→glyph map (Identity-H, 2-byte glyph ids). `rgb` is packed
1095
1123
  * `0xRRGGBB`; `rotationDeg` rotates CCW about `(x, y)`. For a built-in base-14
1096
1124
  * family with no embedding, use {@link addStandardText}.
1097
- */
1098
- addText(page: number, x: number, y: number, size: number, text: string, fontObj: number, rgb?: number, opacity?: number, rotationDeg?: number): boolean;
1125
+ *
1126
+ * Pass `opts` to bake **text decorations** into the run: `{ underline: true }`
1127
+ * draws a rule just below the baseline, `{ strikethrough: true }` a rule near
1128
+ * the x-height — both span the run's advance and are filled in the text colour.
1129
+ * Omitting `opts` is fully backward-compatible (no decoration).
1130
+ */
1131
+ addText(page: number, x: number, y: number, size: number, text: string, fontObj: number, rgb?: number, opacity?: number, rotationDeg?: number, opts?: {
1132
+ underline?: boolean;
1133
+ strikethrough?: boolean;
1134
+ }): boolean;
1099
1135
  /**
1100
1136
  * Draw `text` at `(x, y)` in a built-in **base-14 standard font** (`fontName`,
1101
1137
  * e.g. `"Times-Bold"`, `"Courier-Oblique"`, `"Symbol"`) — no embedding needed,
@@ -1103,8 +1139,15 @@ declare class GigaPdfDoc {
1103
1139
  * {@link embedFont} (a Google Font fetched by the host, or one pulled out of
1104
1140
  * the document with {@link extractFont}) and use {@link addText}. Returns
1105
1141
  * `false` on an unknown font name or bad page.
1142
+ *
1143
+ * Pass `opts` to bake **text decorations** into the run: `{ underline: true }`
1144
+ * and/or `{ strikethrough: true }` draw filled rules in the text colour.
1145
+ * Omitting `opts` is fully backward-compatible (no decoration).
1106
1146
  */
1107
- addStandardText(page: number, x: number, y: number, size: number, text: string, fontName: string, rgb?: number, opacity?: number, rotationDeg?: number): boolean;
1147
+ addStandardText(page: number, x: number, y: number, size: number, text: string, fontName: string, rgb?: number, opacity?: number, rotationDeg?: number, opts?: {
1148
+ underline?: boolean;
1149
+ strikethrough?: boolean;
1150
+ }): boolean;
1108
1151
  /**
1109
1152
  * Stamp a standard-**Helvetica** watermark (no font embed needed): `text` at
1110
1153
  * `(x, y)`, rotated `rotationDeg`° counter-clockwise, `rgb` packed `0xRRGGBB`,
package/dist/index.d.ts CHANGED
@@ -1014,6 +1014,34 @@ declare class GigaPdfDoc {
1014
1014
  addSvg(page: number, svg: string, x: number, y: number, w: number, h: number): boolean;
1015
1015
  /** True redaction: delete content intersecting the region (no opaque cover by default). */
1016
1016
  redact(page: number, x: number, y: number, w: number, h: number, coverRgb?: number, hasCover?: boolean): number;
1017
+ /**
1018
+ * True **PII redaction** of one or more rectangles `(x, y, width, height)` in
1019
+ * PDF points (origin bottom-left), in a single call. For every rect this:
1020
+ *
1021
+ * - **deletes** the overlapping text/vector elements from the content stream —
1022
+ * the glyphs and their `/ToUnicode` mapping are gone, so copy/paste and text
1023
+ * extraction reveal nothing in the area;
1024
+ * - **overwrites the pixels** of any underlying image (a scan/photo) with opaque
1025
+ * black — only the intersecting sub-rectangle, so the rest of the page image
1026
+ * survives — and re-encodes the image, erasing the sensitive pixels from the
1027
+ * bytes (not merely covering them);
1028
+ * - strips overlapping annotations and clears their form-field values;
1029
+ * - paints an opaque **black** box over the rect as the visible redaction mark.
1030
+ *
1031
+ * The black cover is the default for PII (unlike {@link redact}). Pass
1032
+ * `opts.coverRgb` to change the mark colour, or `opts.cover = false` to remove
1033
+ * the content/pixels with no visible box. Returns the number of content
1034
+ * elements deleted across all rects.
1035
+ */
1036
+ redactPii(page: number, rects: {
1037
+ x: number;
1038
+ y: number;
1039
+ width: number;
1040
+ height: number;
1041
+ }[], opts?: {
1042
+ cover?: boolean;
1043
+ coverRgb?: number;
1044
+ }): number;
1017
1045
  rotatePage(page: number, degrees: number): boolean;
1018
1046
  deletePage(page: number): boolean;
1019
1047
  movePage(from: number, to: number): boolean;
@@ -1094,8 +1122,16 @@ declare class GigaPdfDoc {
1094
1122
  * font's char→glyph map (Identity-H, 2-byte glyph ids). `rgb` is packed
1095
1123
  * `0xRRGGBB`; `rotationDeg` rotates CCW about `(x, y)`. For a built-in base-14
1096
1124
  * family with no embedding, use {@link addStandardText}.
1097
- */
1098
- addText(page: number, x: number, y: number, size: number, text: string, fontObj: number, rgb?: number, opacity?: number, rotationDeg?: number): boolean;
1125
+ *
1126
+ * Pass `opts` to bake **text decorations** into the run: `{ underline: true }`
1127
+ * draws a rule just below the baseline, `{ strikethrough: true }` a rule near
1128
+ * the x-height — both span the run's advance and are filled in the text colour.
1129
+ * Omitting `opts` is fully backward-compatible (no decoration).
1130
+ */
1131
+ addText(page: number, x: number, y: number, size: number, text: string, fontObj: number, rgb?: number, opacity?: number, rotationDeg?: number, opts?: {
1132
+ underline?: boolean;
1133
+ strikethrough?: boolean;
1134
+ }): boolean;
1099
1135
  /**
1100
1136
  * Draw `text` at `(x, y)` in a built-in **base-14 standard font** (`fontName`,
1101
1137
  * e.g. `"Times-Bold"`, `"Courier-Oblique"`, `"Symbol"`) — no embedding needed,
@@ -1103,8 +1139,15 @@ declare class GigaPdfDoc {
1103
1139
  * {@link embedFont} (a Google Font fetched by the host, or one pulled out of
1104
1140
  * the document with {@link extractFont}) and use {@link addText}. Returns
1105
1141
  * `false` on an unknown font name or bad page.
1142
+ *
1143
+ * Pass `opts` to bake **text decorations** into the run: `{ underline: true }`
1144
+ * and/or `{ strikethrough: true }` draw filled rules in the text colour.
1145
+ * Omitting `opts` is fully backward-compatible (no decoration).
1106
1146
  */
1107
- addStandardText(page: number, x: number, y: number, size: number, text: string, fontName: string, rgb?: number, opacity?: number, rotationDeg?: number): boolean;
1147
+ addStandardText(page: number, x: number, y: number, size: number, text: string, fontName: string, rgb?: number, opacity?: number, rotationDeg?: number, opts?: {
1148
+ underline?: boolean;
1149
+ strikethrough?: boolean;
1150
+ }): boolean;
1108
1151
  /**
1109
1152
  * Stamp a standard-**Helvetica** watermark (no font embed needed): `text` at
1110
1153
  * `(x, y)`, rotated `rotationDeg`° counter-clockwise, `rgb` packed `0xRRGGBB`,
package/dist/index.js CHANGED
@@ -1045,6 +1045,36 @@ var GigaPdfDoc = class {
1045
1045
  redact(page, x, y, w, h, coverRgb = 0, hasCover = false) {
1046
1046
  return this.ex().gp_redact_region(this.h, page, x, y, w, h, RGB(coverRgb), hasCover ? 1 : 0);
1047
1047
  }
1048
+ /**
1049
+ * True **PII redaction** of one or more rectangles `(x, y, width, height)` in
1050
+ * PDF points (origin bottom-left), in a single call. For every rect this:
1051
+ *
1052
+ * - **deletes** the overlapping text/vector elements from the content stream —
1053
+ * the glyphs and their `/ToUnicode` mapping are gone, so copy/paste and text
1054
+ * extraction reveal nothing in the area;
1055
+ * - **overwrites the pixels** of any underlying image (a scan/photo) with opaque
1056
+ * black — only the intersecting sub-rectangle, so the rest of the page image
1057
+ * survives — and re-encodes the image, erasing the sensitive pixels from the
1058
+ * bytes (not merely covering them);
1059
+ * - strips overlapping annotations and clears their form-field values;
1060
+ * - paints an opaque **black** box over the rect as the visible redaction mark.
1061
+ *
1062
+ * The black cover is the default for PII (unlike {@link redact}). Pass
1063
+ * `opts.coverRgb` to change the mark colour, or `opts.cover = false` to remove
1064
+ * the content/pixels with no visible box. Returns the number of content
1065
+ * elements deleted across all rects.
1066
+ */
1067
+ redactPii(page, rects, opts = {}) {
1068
+ if (rects.length === 0) return 0;
1069
+ const flat = [];
1070
+ for (const r of rects) flat.push(r.x, r.y, r.width, r.height);
1071
+ const cover = opts.cover ?? true;
1072
+ const coverRgb = opts.coverRgb ?? 0;
1073
+ return this.g._withF64(
1074
+ flat,
1075
+ (p, c) => this.ex().gp_redact_pii(this.h, page, p, c, RGB(coverRgb), cover ? 1 : 0)
1076
+ );
1077
+ }
1048
1078
  // pages
1049
1079
  rotatePage(page, degrees) {
1050
1080
  return this.ex().gp_rotate_page(this.h, page, degrees) === 0;
@@ -1194,11 +1224,18 @@ var GigaPdfDoc = class {
1194
1224
  * font's char→glyph map (Identity-H, 2-byte glyph ids). `rgb` is packed
1195
1225
  * `0xRRGGBB`; `rotationDeg` rotates CCW about `(x, y)`. For a built-in base-14
1196
1226
  * family with no embedding, use {@link addStandardText}.
1227
+ *
1228
+ * Pass `opts` to bake **text decorations** into the run: `{ underline: true }`
1229
+ * draws a rule just below the baseline, `{ strikethrough: true }` a rule near
1230
+ * the x-height — both span the run's advance and are filled in the text colour.
1231
+ * Omitting `opts` is fully backward-compatible (no decoration).
1197
1232
  */
1198
- addText(page, x, y, size, text, fontObj, rgb = 0, opacity = 1, rotationDeg = 0) {
1233
+ addText(page, x, y, size, text, fontObj, rgb = 0, opacity = 1, rotationDeg = 0, opts) {
1234
+ const underline = opts?.underline ? 1 : 0;
1235
+ const strikethrough = opts?.strikethrough ? 1 : 0;
1199
1236
  return this.g._withStr(
1200
1237
  text,
1201
- (p, l) => this.ex().gp_add_text(
1238
+ (p, l) => this.ex().gp_add_text_styled(
1202
1239
  this.h,
1203
1240
  page,
1204
1241
  x,
@@ -1209,7 +1246,9 @@ var GigaPdfDoc = class {
1209
1246
  fontObj,
1210
1247
  RGB(rgb),
1211
1248
  opacity,
1212
- rotationDeg
1249
+ rotationDeg,
1250
+ underline,
1251
+ strikethrough
1213
1252
  )
1214
1253
  ) === 0;
1215
1254
  }
@@ -1220,13 +1259,19 @@ var GigaPdfDoc = class {
1220
1259
  * {@link embedFont} (a Google Font fetched by the host, or one pulled out of
1221
1260
  * the document with {@link extractFont}) and use {@link addText}. Returns
1222
1261
  * `false` on an unknown font name or bad page.
1262
+ *
1263
+ * Pass `opts` to bake **text decorations** into the run: `{ underline: true }`
1264
+ * and/or `{ strikethrough: true }` draw filled rules in the text colour.
1265
+ * Omitting `opts` is fully backward-compatible (no decoration).
1223
1266
  */
1224
- addStandardText(page, x, y, size, text, fontName, rgb = 0, opacity = 1, rotationDeg = 0) {
1267
+ addStandardText(page, x, y, size, text, fontName, rgb = 0, opacity = 1, rotationDeg = 0, opts) {
1268
+ const underline = opts?.underline ? 1 : 0;
1269
+ const strikethrough = opts?.strikethrough ? 1 : 0;
1225
1270
  return this.g._withStr(
1226
1271
  text,
1227
1272
  (tp, tl) => this.g._withStr(
1228
1273
  fontName,
1229
- (fp, fl) => this.ex().gp_add_text_standard(
1274
+ (fp, fl) => this.ex().gp_add_text_standard_styled(
1230
1275
  this.h,
1231
1276
  page,
1232
1277
  x,
@@ -1238,7 +1283,9 @@ var GigaPdfDoc = class {
1238
1283
  fl,
1239
1284
  RGB(rgb),
1240
1285
  opacity,
1241
- rotationDeg
1286
+ rotationDeg,
1287
+ underline,
1288
+ strikethrough
1242
1289
  )
1243
1290
  )
1244
1291
  ) === 0;