@ironsoftware/ironpdf 2026.3.1 → 2026.5.1

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.
Files changed (90) hide show
  1. package/package.json +3 -3
  2. package/src/index.d.ts +3 -0
  3. package/src/index.d.ts.map +1 -1
  4. package/src/index.js +6 -2
  5. package/src/index.js.map +1 -1
  6. package/src/index.ts +4 -2
  7. package/src/internal/IronPdfEngine.ProtoFiles/chrome_render.proto +6 -0
  8. package/src/internal/IronPdfEngine.ProtoFiles/iron_pdf_service.proto +2 -1
  9. package/src/internal/IronPdfEngine.ProtoFiles/qpdf.proto +16 -0
  10. package/src/internal/generated_proto/iron_pdf_service.d.ts +614 -305
  11. package/src/internal/generated_proto/iron_pdf_service.d.ts.map +1 -1
  12. package/src/internal/generated_proto/iron_pdf_service.ts +614 -305
  13. package/src/internal/generated_proto/ironpdfengineproto/ChromePdfRenderOptionsP.d.ts +15 -0
  14. package/src/internal/generated_proto/ironpdfengineproto/ChromePdfRenderOptionsP.d.ts.map +1 -1
  15. package/src/internal/generated_proto/ironpdfengineproto/ChromePdfRenderOptionsP.ts +15 -0
  16. package/src/internal/generated_proto/ironpdfengineproto/IronPdfService.d.ts +14 -0
  17. package/src/internal/generated_proto/ironpdfengineproto/IronPdfService.d.ts.map +1 -1
  18. package/src/internal/generated_proto/ironpdfengineproto/IronPdfService.ts +18 -0
  19. package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestIdP.d.ts +10 -0
  20. package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestIdP.d.ts.map +1 -0
  21. package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestIdP.js +4 -0
  22. package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestIdP.js.map +1 -0
  23. package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestIdP.ts +13 -0
  24. package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestStreamP.d.ts +18 -0
  25. package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestStreamP.d.ts.map +1 -0
  26. package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestStreamP.js +4 -0
  27. package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestStreamP.js.map +1 -0
  28. package/src/internal/generated_proto/ironpdfengineproto/QPdfLinearizeInMemoryRequestStreamP.ts +21 -0
  29. package/src/internal/grpc_layer/chrome/converter.d.ts +10 -0
  30. package/src/internal/grpc_layer/chrome/converter.d.ts.map +1 -1
  31. package/src/internal/grpc_layer/chrome/converter.js +61 -2
  32. package/src/internal/grpc_layer/chrome/converter.js.map +1 -1
  33. package/src/internal/grpc_layer/chrome/converter.ts +67 -0
  34. package/src/internal/grpc_layer/pdfium/annotations.d.ts +30 -0
  35. package/src/internal/grpc_layer/pdfium/annotations.d.ts.map +1 -0
  36. package/src/internal/grpc_layer/pdfium/annotations.js +161 -0
  37. package/src/internal/grpc_layer/pdfium/annotations.js.map +1 -0
  38. package/src/internal/grpc_layer/pdfium/annotations.ts +190 -0
  39. package/src/internal/grpc_layer/pdfium/bookmarks.d.ts +7 -0
  40. package/src/internal/grpc_layer/pdfium/bookmarks.d.ts.map +1 -0
  41. package/src/internal/grpc_layer/pdfium/bookmarks.js +53 -0
  42. package/src/internal/grpc_layer/pdfium/bookmarks.js.map +1 -0
  43. package/src/internal/grpc_layer/pdfium/bookmarks.ts +50 -0
  44. package/src/internal/grpc_layer/pdfium/compress.d.ts +1 -0
  45. package/src/internal/grpc_layer/pdfium/compress.d.ts.map +1 -1
  46. package/src/internal/grpc_layer/pdfium/compress.js +31 -1
  47. package/src/internal/grpc_layer/pdfium/compress.js.map +1 -1
  48. package/src/internal/grpc_layer/pdfium/compress.ts +42 -0
  49. package/src/internal/grpc_layer/pdfium/linearize.d.ts +48 -0
  50. package/src/internal/grpc_layer/pdfium/linearize.d.ts.map +1 -0
  51. package/src/internal/grpc_layer/pdfium/linearize.js +309 -0
  52. package/src/internal/grpc_layer/pdfium/linearize.js.map +1 -0
  53. package/src/internal/grpc_layer/pdfium/linearize.ts +338 -0
  54. package/src/internal/grpc_layer/pdfium/pdfa.d.ts +1 -0
  55. package/src/internal/grpc_layer/pdfium/pdfa.d.ts.map +1 -1
  56. package/src/internal/grpc_layer/pdfium/pdfa.js +22 -1
  57. package/src/internal/grpc_layer/pdfium/pdfa.js.map +1 -1
  58. package/src/internal/grpc_layer/pdfium/pdfa.ts +26 -0
  59. package/src/internal/grpc_layer/pdfium/signing.d.ts +2 -1
  60. package/src/internal/grpc_layer/pdfium/signing.d.ts.map +1 -1
  61. package/src/internal/grpc_layer/pdfium/signing.js +38 -1
  62. package/src/internal/grpc_layer/pdfium/signing.js.map +1 -1
  63. package/src/internal/grpc_layer/pdfium/signing.ts +44 -1
  64. package/src/internal/zod/renderSchema.d.ts.map +1 -1
  65. package/src/internal/zod/renderSchema.js +6 -1
  66. package/src/internal/zod/renderSchema.js.map +1 -1
  67. package/src/internal/zod/renderSchema.ts +6 -1
  68. package/src/public/annotation.d.ts +166 -0
  69. package/src/public/annotation.d.ts.map +1 -0
  70. package/src/public/annotation.js +61 -0
  71. package/src/public/annotation.js.map +1 -0
  72. package/src/public/annotation.ts +166 -0
  73. package/src/public/bookmark.d.ts +25 -0
  74. package/src/public/bookmark.d.ts.map +1 -0
  75. package/src/public/bookmark.js +3 -0
  76. package/src/public/bookmark.js.map +1 -0
  77. package/src/public/bookmark.ts +28 -0
  78. package/src/public/pdfDocument.d.ts +194 -2
  79. package/src/public/pdfDocument.d.ts.map +1 -1
  80. package/src/public/pdfDocument.js +388 -1
  81. package/src/public/pdfDocument.js.map +1 -1
  82. package/src/public/pdfDocument.ts +427 -4
  83. package/src/public/render.d.ts +104 -0
  84. package/src/public/render.d.ts.map +1 -1
  85. package/src/public/render.js +35 -1
  86. package/src/public/render.js.map +1 -1
  87. package/src/public/render.ts +101 -0
  88. package/src/public/signature.d.ts +33 -0
  89. package/src/public/signature.d.ts.map +1 -1
  90. package/src/public/signature.ts +34 -0
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getAnnotationCount = exports.addLinkAnnotation = exports.getAnnotations = void 0;
13
+ const access_1 = require("../../access");
14
+ const annotation_1 = require("../../../public/annotation");
15
+ const util_1 = require("../util");
16
+ /**
17
+ * URL prefix used to encode an internal hyperlink (goto-page) target inside the
18
+ * existing {@code Pdfium_Annotation_AddLinkAnnotation} RPC. Must match the
19
+ * {@code InternalLinkPrefixes.InternalLinkPrefix} constant in the C#
20
+ * {@code IronPdf.GrpcLayer.InternalPrefixes} / {@code IronPdfServiceHandler}.
21
+ *
22
+ * <p>The {@code x-} prefix follows RFC 6648 conventions for experimental /
23
+ * private URL schemes and cannot collide with any real URL scheme a user would
24
+ * construct.</p>
25
+ */
26
+ const INTERNAL_LINK_PREFIX = "x-ironpdf-goto-page:";
27
+ /**
28
+ * Retrieve all heterogeneous annotations (text, free-text, link, ...) on a single page
29
+ * via the {@code Pdfium_Annotation_GetAnnotations} unary RPC.
30
+ *
31
+ * The returned wrapped annotations carry one of the proto sub-types ({@code text},
32
+ * {@code freetext}, {@code link}). Callers inspect the {@code annotations} oneof to
33
+ * dispatch by sub-type.
34
+ */
35
+ function getAnnotations(id, pageIndex) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const client = yield access_1.Access.ensureConnection();
38
+ return new Promise((resolve, reject) => {
39
+ client.Pdfium_Annotation_GetAnnotationsRequestP({
40
+ document: { documentId: id },
41
+ pageIndex: pageIndex,
42
+ }, (err, value) => {
43
+ var _a, _b;
44
+ if (err) {
45
+ reject(`${err.name}/n${err.message}`);
46
+ return;
47
+ }
48
+ if (!value) {
49
+ reject("No response from IronPdfEngine for getAnnotations");
50
+ return;
51
+ }
52
+ if (value.exception) {
53
+ (0, util_1.handleRemoteException)(value.exception, reject);
54
+ return;
55
+ }
56
+ resolve((_b = (_a = value.result) === null || _a === void 0 ? void 0 : _a.annotations) !== null && _b !== void 0 ? _b : []);
57
+ });
58
+ });
59
+ });
60
+ }
61
+ exports.getAnnotations = getAnnotations;
62
+ /**
63
+ * Add an internal hyperlink annotation to the document. The link navigates to a
64
+ * destination page within the same PDF when clicked.
65
+ *
66
+ * <p>Reuses the existing {@code Pdfium_Annotation_AddLinkAnnotation} RPC by encoding
67
+ * the destination parameters into a special URL format:
68
+ * {@code x-ironpdf-goto-page:{destPage},{destType},{left},{right},{top},{bottom},{zoom},{showBorder}}.
69
+ * The engine detects this prefix and routes the request to its internal link handler.</p>
70
+ *
71
+ * <p>Mirrors {@code IronPdf.Engines.Pdfium.GrpcPdfClient.AddInternalLinkAnnotation}
72
+ * on the C# side.</p>
73
+ */
74
+ function addLinkAnnotation(id, link) {
75
+ var _a, _b, _c, _d, _e, _f;
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ if (link.pageIndex < 0) {
78
+ throw new Error("Invalid page index when adding link annotation");
79
+ }
80
+ if (link.destinationPageIndex < 0) {
81
+ throw new Error("Invalid destination page index when adding link annotation");
82
+ }
83
+ const client = yield access_1.Access.ensureConnection();
84
+ const destType = (_a = link.destinationType) !== null && _a !== void 0 ? _a : annotation_1.BookmarkDestinations.Page;
85
+ const destLeft = (_b = link.destinationLeft) !== null && _b !== void 0 ? _b : 0;
86
+ const destRight = (_c = link.destinationRight) !== null && _c !== void 0 ? _c : 0;
87
+ const destTop = (_d = link.destinationTop) !== null && _d !== void 0 ? _d : 0;
88
+ const destBottom = (_e = link.destinationBottom) !== null && _e !== void 0 ? _e : 0;
89
+ const destZoom = (_f = link.destinationZoom) !== null && _f !== void 0 ? _f : 0;
90
+ const showBorderFlag = link.showBorder ? 1 : 0;
91
+ // Matches the 8-field encoding produced by C# AddInternalLinkAnnotation:
92
+ // {prefix}{destPageIndex},{destType},{destLeft},{destRight},{destTop},{destBottom},{destZoom},{showBorder}
93
+ const encodedUrl = `${INTERNAL_LINK_PREFIX}${link.destinationPageIndex},${destType},` +
94
+ `${destLeft},${destRight},${destTop},${destBottom},${destZoom},${showBorderFlag}`;
95
+ // Color fallback: the engine parses `color_code` into IronSoftware.Drawing.Color and
96
+ // throws on an empty string. Match the C# AddLinkAnnotation behavior by always
97
+ // sending a valid color — default to black when the caller hasn't specified one.
98
+ const colorCode = link.colorCode && link.colorCode.length > 0 ? link.colorCode : "#000000";
99
+ return new Promise((resolve, reject) => {
100
+ var _a, _b;
101
+ client.Pdfium_Annotation_AddLinkAnnotation({
102
+ document: { documentId: id },
103
+ name: (_a = link.title) !== null && _a !== void 0 ? _a : "",
104
+ url: encodedUrl,
105
+ pageIndex: link.pageIndex,
106
+ rectangle: {
107
+ x: link.x,
108
+ y: link.y,
109
+ width: link.width,
110
+ height: link.height,
111
+ },
112
+ colorCode: colorCode,
113
+ Hidden: (_b = link.hidden) !== null && _b !== void 0 ? _b : false,
114
+ }, (err, value) => {
115
+ if (err) {
116
+ reject(`${err.name}/n${err.message}`);
117
+ return;
118
+ }
119
+ if (!value) {
120
+ reject("No response from IronPdfEngine for addLinkAnnotation");
121
+ return;
122
+ }
123
+ (0, util_1.handleEmptyResultP__Output)(value, reject);
124
+ resolve();
125
+ });
126
+ });
127
+ });
128
+ }
129
+ exports.addLinkAnnotation = addLinkAnnotation;
130
+ /**
131
+ * Retrieve the number of annotations contained on the specified page via the
132
+ * {@code Pdfium_Annotation_GetAnnotationCount} unary RPC.
133
+ */
134
+ function getAnnotationCount(id, pageIndex) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ const client = yield access_1.Access.ensureConnection();
137
+ return new Promise((resolve, reject) => {
138
+ client.Pdfium_Annotation_GetAnnotationCountRequestP({
139
+ document: { documentId: id },
140
+ pageIndex: pageIndex,
141
+ }, (err, value) => {
142
+ var _a;
143
+ if (err) {
144
+ reject(`${err.name}/n${err.message}`);
145
+ return;
146
+ }
147
+ if (!value) {
148
+ reject("No response from IronPdfEngine for getAnnotationCount");
149
+ return;
150
+ }
151
+ if (value.exception) {
152
+ (0, util_1.handleRemoteException)(value.exception, reject);
153
+ return;
154
+ }
155
+ resolve((_a = value.result) !== null && _a !== void 0 ? _a : 0);
156
+ });
157
+ });
158
+ });
159
+ }
160
+ exports.getAnnotationCount = getAnnotationCount;
161
+ //# sourceMappingURL=annotations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotations.js","sourceRoot":"","sources":["annotations.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,yCAAoC;AAKpC,2DAAgF;AAChF,kCAA0E;AAE1E;;;;;;;;;GASG;AACH,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAEpD;;;;;;;GAOG;AACH,SAAsB,cAAc,CACnC,EAAU,EACV,SAAiB;;QAEjB,MAAM,MAAM,GAAyB,MAAM,eAAM,CAAC,gBAAgB,EAAE,CAAC;QAErE,OAAO,IAAI,OAAO,CACjB,CACC,OAA2D,EAC3D,MAAkC,EACjC,EAAE;YACH,MAAM,CAAC,wCAAwC,CAC9C;gBACC,QAAQ,EAAE,EAAC,UAAU,EAAE,EAAE,EAAC;gBAC1B,SAAS,EAAE,SAAS;aACpB,EACD,CACC,GAAwB,EACxB,KAAsD,EACrD,EAAE;;gBACH,IAAI,GAAG,EAAE;oBACR,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,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/D,OAAO;iBACP;gBACD,IAAA,iCAA0B,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;gBAC1C,OAAO,EAAE,CAAC;YACX,CAAC,CACD,CAAC;QACH,CAAC,CACD,CAAC;;CACF;AAnED,8CAmEC;AAED;;;GAGG;AACH,SAAsB,kBAAkB,CACvC,EAAU,EACV,SAAiB;;QAEjB,MAAM,MAAM,GAAyB,MAAM,eAAM,CAAC,gBAAgB,EAAE,CAAC;QAErE,OAAO,IAAI,OAAO,CACjB,CAAC,OAA4B,EAAE,MAAkC,EAAE,EAAE;YACpE,MAAM,CAAC,4CAA4C,CAClD;gBACC,QAAQ,EAAE,EAAC,UAAU,EAAE,EAAE,EAAC;gBAC1B,SAAS,EAAE,SAAS;aACpB,EACD,CACC,GAAwB,EACxB,KAEY,EACX,EAAE;;gBACH,IAAI,GAAG,EAAE;oBACR,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;oBACtC,OAAO;iBACP;gBACD,IAAI,CAAC,KAAK,EAAE;oBACX,MAAM,CAAC,uDAAuD,CAAC,CAAC;oBAChE,OAAO;iBACP;gBACD,IAAI,KAAK,CAAC,SAAS,EAAE;oBACpB,IAAA,4BAAqB,EAAC,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;oBAC/C,OAAO;iBACP;gBACD,OAAO,CAAC,MAAA,KAAK,CAAC,MAAM,mCAAI,CAAC,CAAC,CAAC;YAC5B,CAAC,CACD,CAAC;QACH,CAAC,CACD,CAAC;IACH,CAAC;CAAA;AApCD,gDAoCC"}
@@ -0,0 +1,190 @@
1
+ import {ServiceError} from "@grpc/grpc-js";
2
+ import {Access} from "../../access";
3
+ import {IronPdfServiceClient} from "../../generated_proto/ironpdfengineproto/IronPdfService";
4
+ import {EmptyResultP__Output} from "../../generated_proto/ironpdfengineproto/EmptyResultP";
5
+ import {PdfiumGetAnnotationsResultP__Output} from "../../generated_proto/ironpdfengineproto/PdfiumGetAnnotationsResultP";
6
+ import {PdfiumWrappedPdfAnnotationP__Output} from "../../generated_proto/ironpdfengineproto/PdfiumWrappedPdfAnnotationP";
7
+ import {BookmarkDestinations, LinkAnnotation} from "../../../public/annotation";
8
+ import {handleEmptyResultP__Output, handleRemoteException} from "../util";
9
+
10
+ /**
11
+ * URL prefix used to encode an internal hyperlink (goto-page) target inside the
12
+ * existing {@code Pdfium_Annotation_AddLinkAnnotation} RPC. Must match the
13
+ * {@code InternalLinkPrefixes.InternalLinkPrefix} constant in the C#
14
+ * {@code IronPdf.GrpcLayer.InternalPrefixes} / {@code IronPdfServiceHandler}.
15
+ *
16
+ * <p>The {@code x-} prefix follows RFC 6648 conventions for experimental /
17
+ * private URL schemes and cannot collide with any real URL scheme a user would
18
+ * construct.</p>
19
+ */
20
+ const INTERNAL_LINK_PREFIX = "x-ironpdf-goto-page:";
21
+
22
+ /**
23
+ * Retrieve all heterogeneous annotations (text, free-text, link, ...) on a single page
24
+ * via the {@code Pdfium_Annotation_GetAnnotations} unary RPC.
25
+ *
26
+ * The returned wrapped annotations carry one of the proto sub-types ({@code text},
27
+ * {@code freetext}, {@code link}). Callers inspect the {@code annotations} oneof to
28
+ * dispatch by sub-type.
29
+ */
30
+ export async function getAnnotations(
31
+ id: string,
32
+ pageIndex: number
33
+ ): Promise<PdfiumWrappedPdfAnnotationP__Output[]> {
34
+ const client: IronPdfServiceClient = await Access.ensureConnection();
35
+
36
+ return new Promise(
37
+ (
38
+ resolve: (_: PdfiumWrappedPdfAnnotationP__Output[]) => void,
39
+ reject: (errorMsg: string) => void
40
+ ) => {
41
+ client.Pdfium_Annotation_GetAnnotationsRequestP(
42
+ {
43
+ document: {documentId: id},
44
+ pageIndex: pageIndex,
45
+ },
46
+ (
47
+ err: ServiceError | null,
48
+ value: PdfiumGetAnnotationsResultP__Output | undefined
49
+ ) => {
50
+ if (err) {
51
+ reject(`${err.name}/n${err.message}`);
52
+ return;
53
+ }
54
+ if (!value) {
55
+ reject("No response from IronPdfEngine for getAnnotations");
56
+ return;
57
+ }
58
+ if (value.exception) {
59
+ handleRemoteException(value.exception, reject);
60
+ return;
61
+ }
62
+ resolve(value.result?.annotations ?? []);
63
+ }
64
+ );
65
+ }
66
+ );
67
+ }
68
+
69
+ /**
70
+ * Add an internal hyperlink annotation to the document. The link navigates to a
71
+ * destination page within the same PDF when clicked.
72
+ *
73
+ * <p>Reuses the existing {@code Pdfium_Annotation_AddLinkAnnotation} RPC by encoding
74
+ * the destination parameters into a special URL format:
75
+ * {@code x-ironpdf-goto-page:{destPage},{destType},{left},{right},{top},{bottom},{zoom},{showBorder}}.
76
+ * The engine detects this prefix and routes the request to its internal link handler.</p>
77
+ *
78
+ * <p>Mirrors {@code IronPdf.Engines.Pdfium.GrpcPdfClient.AddInternalLinkAnnotation}
79
+ * on the C# side.</p>
80
+ */
81
+ export async function addLinkAnnotation(
82
+ id: string,
83
+ link: LinkAnnotation
84
+ ): Promise<void> {
85
+ if (link.pageIndex < 0) {
86
+ throw new Error("Invalid page index when adding link annotation");
87
+ }
88
+ if (link.destinationPageIndex < 0) {
89
+ throw new Error("Invalid destination page index when adding link annotation");
90
+ }
91
+
92
+ const client: IronPdfServiceClient = await Access.ensureConnection();
93
+
94
+ const destType: BookmarkDestinations = link.destinationType ?? BookmarkDestinations.Page;
95
+ const destLeft = link.destinationLeft ?? 0;
96
+ const destRight = link.destinationRight ?? 0;
97
+ const destTop = link.destinationTop ?? 0;
98
+ const destBottom = link.destinationBottom ?? 0;
99
+ const destZoom = link.destinationZoom ?? 0;
100
+ const showBorderFlag = link.showBorder ? 1 : 0;
101
+
102
+ // Matches the 8-field encoding produced by C# AddInternalLinkAnnotation:
103
+ // {prefix}{destPageIndex},{destType},{destLeft},{destRight},{destTop},{destBottom},{destZoom},{showBorder}
104
+ const encodedUrl =
105
+ `${INTERNAL_LINK_PREFIX}${link.destinationPageIndex},${destType},` +
106
+ `${destLeft},${destRight},${destTop},${destBottom},${destZoom},${showBorderFlag}`;
107
+
108
+ // Color fallback: the engine parses `color_code` into IronSoftware.Drawing.Color and
109
+ // throws on an empty string. Match the C# AddLinkAnnotation behavior by always
110
+ // sending a valid color — default to black when the caller hasn't specified one.
111
+ const colorCode = link.colorCode && link.colorCode.length > 0 ? link.colorCode : "#000000";
112
+
113
+ return new Promise(
114
+ (resolve: () => void, reject: (errorMsg: string) => void) => {
115
+ client.Pdfium_Annotation_AddLinkAnnotation(
116
+ {
117
+ document: {documentId: id},
118
+ name: link.title ?? "",
119
+ url: encodedUrl,
120
+ pageIndex: link.pageIndex,
121
+ rectangle: {
122
+ x: link.x,
123
+ y: link.y,
124
+ width: link.width,
125
+ height: link.height,
126
+ },
127
+ colorCode: colorCode,
128
+ Hidden: link.hidden ?? false,
129
+ },
130
+ (
131
+ err: ServiceError | null,
132
+ value: EmptyResultP__Output | undefined
133
+ ) => {
134
+ if (err) {
135
+ reject(`${err.name}/n${err.message}`);
136
+ return;
137
+ }
138
+ if (!value) {
139
+ reject("No response from IronPdfEngine for addLinkAnnotation");
140
+ return;
141
+ }
142
+ handleEmptyResultP__Output(value, reject);
143
+ resolve();
144
+ }
145
+ );
146
+ }
147
+ );
148
+ }
149
+
150
+ /**
151
+ * Retrieve the number of annotations contained on the specified page via the
152
+ * {@code Pdfium_Annotation_GetAnnotationCount} unary RPC.
153
+ */
154
+ export async function getAnnotationCount(
155
+ id: string,
156
+ pageIndex: number
157
+ ): Promise<number> {
158
+ const client: IronPdfServiceClient = await Access.ensureConnection();
159
+
160
+ return new Promise(
161
+ (resolve: (_: number) => void, reject: (errorMsg: string) => void) => {
162
+ client.Pdfium_Annotation_GetAnnotationCountRequestP(
163
+ {
164
+ document: {documentId: id},
165
+ pageIndex: pageIndex,
166
+ },
167
+ (
168
+ err: ServiceError | null,
169
+ value:
170
+ | import("../../generated_proto/ironpdfengineproto/IntResultP").IntResultP__Output
171
+ | undefined
172
+ ) => {
173
+ if (err) {
174
+ reject(`${err.name}/n${err.message}`);
175
+ return;
176
+ }
177
+ if (!value) {
178
+ reject("No response from IronPdfEngine for getAnnotationCount");
179
+ return;
180
+ }
181
+ if (value.exception) {
182
+ handleRemoteException(value.exception, reject);
183
+ return;
184
+ }
185
+ resolve(value.result ?? 0);
186
+ }
187
+ );
188
+ }
189
+ );
190
+ }
@@ -0,0 +1,7 @@
1
+ import { Bookmark } from "../../../public/bookmark";
2
+ /**
3
+ * Retrieve the document's outline bookmarks via the {@code Pdfium_Bookmark_GetBookmarksDescriptor}
4
+ * unary RPC. Mirrors {@code IronPdf.PdfDocument.Bookmarks} on the C# side.
5
+ */
6
+ export declare function getBookmarks(id: string): Promise<Bookmark[]>;
7
+ //# sourceMappingURL=bookmarks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bookmarks.d.ts","sourceRoot":"","sources":["bookmarks.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,QAAQ,EAAC,MAAM,0BAA0B,CAAC;AAGlD;;;GAGG;AACH,wBAAsB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAsClE"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getBookmarks = void 0;
13
+ const access_1 = require("../../access");
14
+ const util_1 = require("../util");
15
+ /**
16
+ * Retrieve the document's outline bookmarks via the {@code Pdfium_Bookmark_GetBookmarksDescriptor}
17
+ * unary RPC. Mirrors {@code IronPdf.PdfDocument.Bookmarks} on the C# side.
18
+ */
19
+ function getBookmarks(id) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const client = yield access_1.Access.ensureConnection();
22
+ return new Promise((resolve, reject) => {
23
+ client.Pdfium_Bookmark_GetBookmarksDescriptor({ document: { documentId: id } }, (err, value) => {
24
+ var _a, _b;
25
+ if (err) {
26
+ reject(`${err.name}/n${err.message}`);
27
+ return;
28
+ }
29
+ if (!value) {
30
+ reject("No response from IronPdfEngine for getBookmarks");
31
+ return;
32
+ }
33
+ if (value.exception) {
34
+ (0, util_1.handleRemoteException)(value.exception, reject);
35
+ return;
36
+ }
37
+ const descriptors = (_b = (_a = value.result) === null || _a === void 0 ? void 0 : _a.bookmarkDescriptors) !== null && _b !== void 0 ? _b : [];
38
+ resolve(descriptors.map(d => {
39
+ var _a, _b, _c, _d, _e;
40
+ return ({
41
+ text: (_a = d.text) !== null && _a !== void 0 ? _a : "",
42
+ pageIndex: (_b = d.pageIndex) !== null && _b !== void 0 ? _b : 0,
43
+ hierarchy: (_c = d.hierarchy) !== null && _c !== void 0 ? _c : "",
44
+ itemId: (_d = d.itemId) !== null && _d !== void 0 ? _d : "",
45
+ parentItemId: (_e = d.parentItemId) !== null && _e !== void 0 ? _e : "",
46
+ });
47
+ }));
48
+ });
49
+ });
50
+ });
51
+ }
52
+ exports.getBookmarks = getBookmarks;
53
+ //# sourceMappingURL=bookmarks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bookmarks.js","sourceRoot":"","sources":["bookmarks.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,yCAAoC;AAIpC,kCAA8C;AAE9C;;;GAGG;AACH,SAAsB,YAAY,CAAC,EAAU;;QAC5C,MAAM,MAAM,GAAyB,MAAM,eAAM,CAAC,gBAAgB,EAAE,CAAC;QAErE,OAAO,IAAI,OAAO,CACjB,CAAC,OAAgC,EAAE,MAAkC,EAAE,EAAE;YACxE,MAAM,CAAC,sCAAsC,CAC5C,EAAC,QAAQ,EAAE,EAAC,UAAU,EAAE,EAAE,EAAC,EAAC,EAC5B,CACC,GAAwB,EACxB,KAA8D,EAC7D,EAAE;;gBACH,IAAI,GAAG,EAAE;oBACR,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;oBACtC,OAAO;iBACP;gBACD,IAAI,CAAC,KAAK,EAAE;oBACX,MAAM,CAAC,iDAAiD,CAAC,CAAC;oBAC1D,OAAO;iBACP;gBACD,IAAI,KAAK,CAAC,SAAS,EAAE;oBACpB,IAAA,4BAAqB,EAAC,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;oBAC/C,OAAO;iBACP;gBAED,MAAM,WAAW,GAAG,MAAA,MAAA,KAAK,CAAC,MAAM,0CAAE,mBAAmB,mCAAI,EAAE,CAAC;gBAC5D,OAAO,CACN,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;;oBAAC,OAAA,CAAC;wBACrB,IAAI,EAAE,MAAA,CAAC,CAAC,IAAI,mCAAI,EAAE;wBAClB,SAAS,EAAE,MAAA,CAAC,CAAC,SAAS,mCAAI,CAAC;wBAC3B,SAAS,EAAE,MAAA,CAAC,CAAC,SAAS,mCAAI,EAAE;wBAC5B,MAAM,EAAE,MAAA,CAAC,CAAC,MAAM,mCAAI,EAAE;wBACtB,YAAY,EAAE,MAAA,CAAC,CAAC,YAAY,mCAAI,EAAE;qBAClC,CAAC,CAAA;iBAAA,CAAC,CACH,CAAC;YACH,CAAC,CACD,CAAC;QACH,CAAC,CACD,CAAC;IACH,CAAC;CAAA;AAtCD,oCAsCC"}
@@ -0,0 +1,50 @@
1
+ import {ServiceError} from "@grpc/grpc-js";
2
+ import {Access} from "../../access";
3
+ import {IronPdfServiceClient} from "../../generated_proto/ironpdfengineproto/IronPdfService";
4
+ import {PdfiumGetBookmarksDescriptorResultP__Output} from "../../generated_proto/ironpdfengineproto/PdfiumGetBookmarksDescriptorResultP";
5
+ import {Bookmark} from "../../../public/bookmark";
6
+ import {handleRemoteException} from "../util";
7
+
8
+ /**
9
+ * Retrieve the document's outline bookmarks via the {@code Pdfium_Bookmark_GetBookmarksDescriptor}
10
+ * unary RPC. Mirrors {@code IronPdf.PdfDocument.Bookmarks} on the C# side.
11
+ */
12
+ export async function getBookmarks(id: string): Promise<Bookmark[]> {
13
+ const client: IronPdfServiceClient = await Access.ensureConnection();
14
+
15
+ return new Promise(
16
+ (resolve: (_: Bookmark[]) => void, reject: (errorMsg: string) => void) => {
17
+ client.Pdfium_Bookmark_GetBookmarksDescriptor(
18
+ {document: {documentId: id}},
19
+ (
20
+ err: ServiceError | null,
21
+ value: PdfiumGetBookmarksDescriptorResultP__Output | undefined
22
+ ) => {
23
+ if (err) {
24
+ reject(`${err.name}/n${err.message}`);
25
+ return;
26
+ }
27
+ if (!value) {
28
+ reject("No response from IronPdfEngine for getBookmarks");
29
+ return;
30
+ }
31
+ if (value.exception) {
32
+ handleRemoteException(value.exception, reject);
33
+ return;
34
+ }
35
+
36
+ const descriptors = value.result?.bookmarkDescriptors ?? [];
37
+ resolve(
38
+ descriptors.map(d => ({
39
+ text: d.text ?? "",
40
+ pageIndex: d.pageIndex ?? 0,
41
+ hierarchy: d.hierarchy ?? "",
42
+ itemId: d.itemId ?? "",
43
+ parentItemId: d.parentItemId ?? "",
44
+ }))
45
+ );
46
+ }
47
+ );
48
+ }
49
+ );
50
+ }
@@ -4,6 +4,7 @@
4
4
  import { Readable } from "stream";
5
5
  export declare function compressImage(id: string, imageQuality: number, scaleToVisibleSize?: boolean): Promise<void>;
6
6
  export declare function compressStructTree(id: string): Promise<void>;
7
+ export declare function compressAndSaveAs(id: string, outputPath: string, imageQuality?: number): Promise<void>;
7
8
  export declare function compressInMemory(id: string, imageQuality?: number): Promise<Buffer>;
8
9
  export declare function compressInMemoryStream(id: string, imageQuality?: number): Promise<Readable>;
9
10
  //# sourceMappingURL=compress.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compress.d.ts","sourceRoot":"","sources":["compress.ts"],"names":[],"mappings":";;;AAOA,OAAO,EAAc,QAAQ,EAAC,MAAM,QAAQ,CAAC;AAE7C,wBAAsB,aAAa,CAClC,EAAE,EAAE,MAAM,EACV,YAAY,EAAE,MAAM,EACpB,kBAAkB,UAAQ,GACxB,OAAO,CAAC,IAAI,CAAC,CAwBf;AAED,wBAAsB,kBAAkB,CACvC,EAAE,EAAE,MAAM,GACR,OAAO,CAAC,IAAI,CAAC,CAsBf;AAED,wBAAsB,gBAAgB,CACrC,EAAE,EAAE,MAAM,EACV,YAAY,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,CAAC,CAkCjB;AAED,wBAAsB,sBAAsB,CAC3C,EAAE,EAAE,MAAM,EACV,YAAY,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,QAAQ,CAAC,CAiCnB"}
1
+ {"version":3,"file":"compress.d.ts","sourceRoot":"","sources":["compress.ts"],"names":[],"mappings":";;;AAOA,OAAO,EAAc,QAAQ,EAAC,MAAM,QAAQ,CAAC;AAG7C,wBAAsB,aAAa,CAClC,EAAE,EAAE,MAAM,EACV,YAAY,EAAE,MAAM,EACpB,kBAAkB,UAAQ,GACxB,OAAO,CAAC,IAAI,CAAC,CAwBf;AAED,wBAAsB,kBAAkB,CACvC,EAAE,EAAE,MAAM,GACR,OAAO,CAAC,IAAI,CAAC,CAsBf;AAED,wBAAsB,iBAAiB,CACtC,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,MAAM,EAClB,YAAY,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC,CAmCf;AAED,wBAAsB,gBAAgB,CACrC,EAAE,EAAE,MAAM,EACV,YAAY,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,CAAC,CAkCjB;AAED,wBAAsB,sBAAsB,CAC3C,EAAE,EAAE,MAAM,EACV,YAAY,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,QAAQ,CAAC,CAiCnB"}
@@ -8,11 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.compressInMemoryStream = exports.compressInMemory = exports.compressStructTree = exports.compressImage = void 0;
15
+ exports.compressInMemoryStream = exports.compressInMemory = exports.compressAndSaveAs = exports.compressStructTree = exports.compressImage = void 0;
13
16
  const access_1 = require("../../access");
14
17
  const util_1 = require("../util");
15
18
  const stream_1 = require("stream");
19
+ const fs_1 = __importDefault(require("fs"));
16
20
  function compressImage(id, imageQuality, scaleToVisibleSize = false) {
17
21
  return __awaiter(this, void 0, void 0, function* () {
18
22
  const client = yield access_1.Access.ensureConnection();
@@ -53,6 +57,32 @@ function compressStructTree(id) {
53
57
  });
54
58
  }
55
59
  exports.compressStructTree = compressStructTree;
60
+ function compressAndSaveAs(id, outputPath, imageQuality) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const client = yield access_1.Access.ensureConnection();
63
+ return new Promise((resolve, reject) => {
64
+ const request = Object.assign({ document: { documentId: id }, outputPath: "", password: "" }, (imageQuality !== undefined ? { jpeg: imageQuality } : {}));
65
+ const stream = client.QPdf_Compression_CompressAndSaveAs(request);
66
+ const buffers = [];
67
+ stream.on("data", (data) => {
68
+ if (data.exception) {
69
+ reject(`${data.exception.message}/n${data.exception.remoteStackTrace}`);
70
+ }
71
+ else if (data.resultChunk) {
72
+ buffers.push(data.resultChunk);
73
+ }
74
+ });
75
+ stream.on("error", (err) => {
76
+ reject(`${err.name}/n${err.message}`);
77
+ });
78
+ stream.on("end", () => {
79
+ fs_1.default.writeFileSync(outputPath, Buffer.concat(buffers));
80
+ resolve();
81
+ });
82
+ });
83
+ });
84
+ }
85
+ exports.compressAndSaveAs = compressAndSaveAs;
56
86
  function compressInMemory(id, imageQuality) {
57
87
  return __awaiter(this, void 0, void 0, function* () {
58
88
  const client = yield access_1.Access.ensureConnection();
@@ -1 +1 @@
1
- {"version":3,"file":"compress.js","sourceRoot":"","sources":["compress.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,yCAAoC;AAGpC,kCAAmD;AACnD,mCAA6C;AAE7C,SAAsB,aAAa,CAClC,EAAU,EACV,YAAoB,EACpB,kBAAkB,GAAG,KAAK;;QAE1B,MAAM,MAAM,GAAyB,MAAM,eAAM,CAAC,gBAAgB,EAAE,CAAC;QACrE,OAAO,IAAI,OAAO,CACjB,CAAC,OAAmB,EAAE,MAAkC,EAAE,EAAE;YAC3D,MAAM,CAAC,8BAA8B,CACpC;gBACC,QAAQ,EAAE,EAAC,UAAU,EAAE,EAAE,EAAC;gBAC1B,kBAAkB,EAAE,kBAAkB;gBACtC,OAAO,EAAE,YAAY;aACrB,EACD,CACC,GAAwB,EACxB,KAAuC,EACtC,EAAE;gBACH,IAAI,GAAG,EAAE;oBACR,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;iBACtC;qBAAM,IAAI,KAAK,EAAE;oBACjB,IAAA,iCAA0B,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;oBAC1C,OAAO,EAAE,CAAC;iBACV;YACF,CAAC,CACD,CAAC;QACH,CAAC,CACD,CAAC;IACH,CAAC;CAAA;AA5BD,sCA4BC;AAED,SAAsB,kBAAkB,CACvC,EAAU;;QAEV,MAAM,MAAM,GAAyB,MAAM,eAAM,CAAC,gBAAgB,EAAE,CAAC;QACrE,OAAO,IAAI,OAAO,CACjB,CAAC,OAAmB,EAAE,MAAkC,EAAE,EAAE;YAC3D,MAAM,CAAC,gCAAgC,CACtC;gBACC,QAAQ,EAAE,EAAC,UAAU,EAAE,EAAE,EAAC;aAC1B,EACD,CACC,GAAwB,EACxB,KAAuC,EACtC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K,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,CAC1E,CAAC;aACF;iBAAM,IAAI,IAAI,CAAC,WAAW,EAAE;gBAC5B,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;aACpC;QACF,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE;YACjC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACrB,WAAW,CAAC,GAAG,EAAE,CAAC;QACnB,CAAC,CAAC,CAAC;QAEH,OAAO,WAAW,CAAC;IACpB,CAAC;CAAA;AApCD,wDAoCC"}
@@ -6,6 +6,7 @@ import {EmptyResultP__Output} from "../../generated_proto/ironpdfengineproto/Emp
6
6
  import {BytesResultStreamP__Output} from "../../generated_proto/ironpdfengineproto/BytesResultStreamP";
7
7
  import {handleEmptyResultP__Output} from "../util";
8
8
  import {PassThrough, Readable} from "stream";
9
+ import fs from "fs";
9
10
 
10
11
  export async function compressImage(
11
12
  id: string,
@@ -63,6 +64,47 @@ export async function compressStructTree(
63
64
  );
64
65
  }
65
66
 
67
+ export async function compressAndSaveAs(
68
+ id: string,
69
+ outputPath: string,
70
+ imageQuality?: number
71
+ ): Promise<void> {
72
+ const client: IronPdfServiceClient = await Access.ensureConnection();
73
+
74
+ return new Promise(
75
+ (resolve: () => void, reject: (errorMsg: string) => void) => {
76
+ const request = {
77
+ document: {documentId: id},
78
+ outputPath: "",
79
+ password: "",
80
+ ...(imageQuality !== undefined ? {jpeg: imageQuality} : {}),
81
+ };
82
+ const stream: grpc.ClientReadableStream<BytesResultStreamP__Output> =
83
+ client.QPdf_Compression_CompressAndSaveAs(request);
84
+
85
+ const buffers: Buffer[] = [];
86
+ stream.on("data", (data: BytesResultStreamP__Output) => {
87
+ if (data.exception) {
88
+ reject(
89
+ `${data.exception.message}/n${data.exception.remoteStackTrace}`
90
+ );
91
+ } else if (data.resultChunk) {
92
+ buffers.push(data.resultChunk);
93
+ }
94
+ });
95
+
96
+ stream.on("error", (err: Error) => {
97
+ reject(`${err.name}/n${err.message}`);
98
+ });
99
+
100
+ stream.on("end", () => {
101
+ fs.writeFileSync(outputPath, Buffer.concat(buffers));
102
+ resolve();
103
+ });
104
+ }
105
+ );
106
+ }
107
+
66
108
  export async function compressInMemory(
67
109
  id: string,
68
110
  imageQuality?: number