@ironsoftware/ironpdf 2024.1.1 → 2024.3.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.
- package/package.json +4 -3
- package/src/internal/IronPdfEngine.ProtoFiles/chrome_render.proto +2 -1
- package/src/internal/IronPdfEngine.ProtoFiles/iron_pdf_service.proto +3 -0
- package/src/internal/IronPdfEngine.ProtoFiles/pdfium_compress.proto +1 -0
- package/src/internal/IronPdfEngine.ProtoFiles/pdfium_form.proto +1 -5
- package/src/internal/IronPdfEngine.ProtoFiles/pdfium_pdf_document.proto +58 -0
- package/src/internal/IronPdfEngine.ProtoFiles/pdfium_signature.proto +1 -0
- package/src/internal/IronPdfEngine.ProtoFiles/pdfium_text.proto +7 -0
- package/src/internal/generated_proto/iron_pdf_service.d.ts +9 -1
- package/src/internal/generated_proto/iron_pdf_service.d.ts.map +1 -1
- package/src/internal/generated_proto/iron_pdf_service.ts +9 -1
- package/src/internal/generated_proto/ironpdfengineproto/ChromeTextHeaderFooterP.d.ts +3 -3
- package/src/internal/generated_proto/ironpdfengineproto/ChromeTextHeaderFooterP.d.ts.map +1 -1
- package/src/internal/generated_proto/ironpdfengineproto/ChromeTextHeaderFooterP.ts +3 -3
- package/src/internal/generated_proto/ironpdfengineproto/IronPdfService.d.ts +35 -0
- package/src/internal/generated_proto/ironpdfengineproto/IronPdfService.d.ts.map +1 -1
- package/src/internal/generated_proto/ironpdfengineproto/IronPdfService.ts +41 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCharObjectCollectionP.d.ts +8 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCharObjectCollectionP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCharObjectCollectionP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCharObjectCollectionP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCharObjectCollectionP.ts +11 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCharObjectP.d.ts +25 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCharObjectP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCharObjectP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCharObjectP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCharObjectP.ts +28 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCompressImagesRequestP.d.ts +2 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCompressImagesRequestP.d.ts.map +1 -1
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumCompressImagesRequestP.ts +2 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumFormFieldP.d.ts +2 -3
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumFormFieldP.d.ts.map +1 -1
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumFormFieldP.ts +2 -3
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetCharObjectCollectionRequestP.d.ts +10 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetCharObjectCollectionRequestP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetCharObjectCollectionRequestP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetCharObjectCollectionRequestP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetCharObjectCollectionRequestP.ts +13 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetCharObjectCollectionResultP.d.ts +12 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetCharObjectCollectionResultP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetCharObjectCollectionResultP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetCharObjectCollectionResultP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetCharObjectCollectionResultP.ts +15 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetTextObjectCollectionRequestP.d.ts +10 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetTextObjectCollectionRequestP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetTextObjectCollectionRequestP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetTextObjectCollectionRequestP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetTextObjectCollectionRequestP.ts +13 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetTextObjectCollectionResultP.d.ts +12 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetTextObjectCollectionResultP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetTextObjectCollectionResultP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetTextObjectCollectionResultP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumGetTextObjectCollectionResultP.ts +15 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumRedactTextRequestP.d.ts +14 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumRedactTextRequestP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumRedactTextRequestP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumRedactTextRequestP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumRedactTextRequestP.ts +17 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumSignRequestStreamP.d.ts +3 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumSignRequestStreamP.d.ts.map +1 -1
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumSignRequestStreamP.ts +3 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumTextObjectCollectionP.d.ts +8 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumTextObjectCollectionP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumTextObjectCollectionP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumTextObjectCollectionP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumTextObjectCollectionP.ts +11 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumTextObjectP.d.ts +17 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumTextObjectP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumTextObjectP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumTextObjectP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumTextObjectP.ts +20 -0
- package/src/internal/grpc_layer/chrome/stamp.d.ts +3 -3
- package/src/internal/grpc_layer/chrome/stamp.d.ts.map +1 -1
- package/src/internal/grpc_layer/chrome/stamp.js +3 -3
- package/src/internal/grpc_layer/chrome/stamp.js.map +1 -1
- package/src/internal/grpc_layer/chrome/stamp.ts +6 -6
- package/src/internal/grpc_layer/pdfium/page.d.ts +1 -1
- package/src/internal/grpc_layer/pdfium/page.d.ts.map +1 -1
- package/src/internal/grpc_layer/pdfium/page.js +1 -1
- package/src/internal/grpc_layer/pdfium/page.js.map +1 -1
- package/src/internal/grpc_layer/pdfium/page.ts +2 -3
- package/src/internal/zod/affixSchema.d.ts +6 -0
- package/src/internal/zod/affixSchema.d.ts.map +1 -0
- package/src/internal/zod/affixSchema.js +36 -0
- package/src/internal/zod/affixSchema.js.map +1 -0
- package/src/internal/zod/affixSchema.ts +35 -0
- package/src/internal/zod/imageSchema.d.ts +6 -0
- package/src/internal/zod/imageSchema.d.ts.map +1 -0
- package/src/internal/zod/imageSchema.js +13 -0
- package/src/internal/zod/imageSchema.js.map +1 -0
- package/src/internal/zod/imageSchema.ts +18 -0
- package/src/internal/zod/ironpdfglobalconfigSchema.d.ts +4 -0
- package/src/internal/zod/ironpdfglobalconfigSchema.d.ts.map +1 -0
- package/src/internal/zod/ironpdfglobalconfigSchema.js +34 -0
- package/src/internal/zod/ironpdfglobalconfigSchema.js.map +1 -0
- package/src/internal/zod/ironpdfglobalconfigSchema.ts +32 -0
- package/src/internal/zod/pageSchema.d.ts +5 -0
- package/src/internal/zod/pageSchema.d.ts.map +1 -0
- package/src/internal/zod/pageSchema.js +18 -0
- package/src/internal/zod/pageSchema.js.map +1 -0
- package/src/internal/zod/pageSchema.ts +17 -0
- package/src/internal/zod/paperSchema.d.ts +8 -0
- package/src/internal/zod/paperSchema.d.ts.map +1 -0
- package/src/internal/zod/paperSchema.js +18 -0
- package/src/internal/zod/paperSchema.js.map +1 -0
- package/src/internal/zod/paperSchema.ts +22 -0
- package/src/internal/zod/pdfDocumentSchema.d.ts +4 -0
- package/src/internal/zod/pdfDocumentSchema.d.ts.map +1 -0
- package/src/internal/zod/pdfDocumentSchema.js +7 -0
- package/src/internal/zod/pdfDocumentSchema.js.map +1 -0
- package/src/internal/zod/pdfDocumentSchema.ts +6 -0
- package/src/internal/zod/renderSchema.d.ts +14 -0
- package/src/internal/zod/renderSchema.d.ts.map +1 -0
- package/src/internal/zod/renderSchema.js +88 -0
- package/src/internal/zod/renderSchema.js.map +1 -0
- package/src/internal/zod/renderSchema.ts +107 -0
- package/src/internal/zod/securitySchema.d.ts +4 -0
- package/src/internal/zod/securitySchema.d.ts.map +1 -0
- package/src/internal/zod/securitySchema.js +17 -0
- package/src/internal/zod/securitySchema.js.map +1 -0
- package/src/internal/zod/securitySchema.ts +15 -0
- package/src/internal/zod/signatureSchema.d.ts +5 -0
- package/src/internal/zod/signatureSchema.d.ts.map +1 -0
- package/src/internal/zod/signatureSchema.js +22 -0
- package/src/internal/zod/signatureSchema.js.map +1 -0
- package/src/internal/zod/signatureSchema.ts +22 -0
- package/src/internal/zod/stampSchema.d.ts +155 -0
- package/src/internal/zod/stampSchema.d.ts.map +1 -0
- package/src/internal/zod/stampSchema.js +79 -0
- package/src/internal/zod/stampSchema.js.map +1 -0
- package/src/internal/zod/stampSchema.ts +87 -0
- package/src/internal/zod/typeSchema.d.ts +38 -0
- package/src/internal/zod/typeSchema.d.ts.map +1 -0
- package/src/internal/zod/typeSchema.js +74 -0
- package/src/internal/zod/typeSchema.js.map +1 -0
- package/src/internal/zod/typeSchema.ts +120 -0
- package/src/public/affix.d.ts +5 -5
- package/src/public/affix.ts +5 -5
- package/src/public/image.d.ts +1 -9
- package/src/public/image.d.ts.map +1 -1
- package/src/public/image.js.map +1 -1
- package/src/public/image.ts +1 -9
- package/src/public/ironpdfglobalconfig.d.ts +8 -8
- package/src/public/ironpdfglobalconfig.ts +8 -8
- package/src/public/pdfDocument.d.ts +354 -43
- package/src/public/pdfDocument.d.ts.map +1 -1
- package/src/public/pdfDocument.js +835 -150
- package/src/public/pdfDocument.js.map +1 -1
- package/src/public/pdfDocument.ts +1125 -197
- package/src/public/pdfGenerator.d.ts +4 -4
- package/src/public/pdfGenerator.ts +4 -4
- package/src/public/render.d.ts +5 -5
- package/src/public/render.ts +5 -5
- package/src/public/stamp.d.ts +10 -10
- package/src/public/stamp.ts +11 -11
- package/src/public/types.d.ts +7 -7
- package/src/public/types.d.ts.map +1 -1
- package/src/public/types.js.map +1 -1
- package/src/public/types.ts +7 -8
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumFormFieldTypesP.d.ts +0 -7
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumFormFieldTypesP.d.ts.map +0 -1
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumFormFieldTypesP.js +0 -4
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumFormFieldTypesP.js.map +0 -1
- package/src/internal/generated_proto/ironpdfengineproto/PdfiumFormFieldTypesP.ts +0 -10
|
@@ -19,89 +19,1015 @@ import {
|
|
|
19
19
|
PdfInput,
|
|
20
20
|
PdfPageSelection,
|
|
21
21
|
PdfPaperSize,
|
|
22
|
-
PdfPassword,
|
|
23
|
-
PdfPermission,
|
|
22
|
+
PdfPassword, PdfPermission,
|
|
24
23
|
SaveOptions,
|
|
25
24
|
TextAffix,
|
|
26
25
|
TextStampOptions,
|
|
27
26
|
} from "./types";
|
|
28
|
-
|
|
27
|
+
|
|
28
|
+
import {
|
|
29
|
+
barcodeTypeSchema, booleanSchema, bufferArraySchema, bufferSchema, changeTrackingModesSchema,
|
|
30
|
+
filePathSchema,
|
|
31
|
+
htmlFilePathSchema,
|
|
32
|
+
htmlStringSchema,
|
|
33
|
+
imageBufferSchema,
|
|
34
|
+
imageFilePathSchema,
|
|
35
|
+
mapStringSchema,
|
|
36
|
+
numberSchema, pdfFilePathSchema,
|
|
37
|
+
pdfInputSchema,
|
|
38
|
+
pdfPageSelectionSchema, pdfPasswordSchema, saveOptionsSchema, stringArraySchema,
|
|
39
|
+
stringSchema, urlSchema
|
|
40
|
+
} from "../internal/zod/typeSchema";
|
|
41
|
+
import {z} from "zod";
|
|
42
|
+
import {pdfPermissionSchema} from "../internal/zod/securitySchema";
|
|
43
|
+
import {pdfDocumentSchema} from "../internal/zod/pdfDocumentSchema";
|
|
44
|
+
import {
|
|
45
|
+
barcodeStampOptionsSchema,
|
|
46
|
+
htmlStampOptionsSchema,
|
|
47
|
+
imageStampOptionsSchema,
|
|
48
|
+
textStampOptionsSchema
|
|
49
|
+
} from "../internal/zod/stampSchema";
|
|
50
|
+
import {htmlAffixSchema, textAffixSchema} from "../internal/zod/affixSchema";
|
|
51
|
+
import {digitalSignatureSchema} from "../internal/zod/signatureSchema";
|
|
52
|
+
import {imageToPdfOptionsSchema, imageTypeSchema} from "../internal/zod/imageSchema";
|
|
53
|
+
import {pdfPaperSizeSchema} from "../internal/zod/paperSchema";
|
|
54
|
+
import {pageRotationSchema} from "../internal/zod/pageSchema";
|
|
55
|
+
import {chromePdfRenderOptionsSchema, httpLoginCredentialsSchema} from "../internal/zod/renderSchema";
|
|
29
56
|
import {
|
|
30
57
|
getFileNames,
|
|
31
58
|
getImageExtType,
|
|
32
59
|
separateImageBufferOrImagePathInput,
|
|
33
|
-
separatePdfInput
|
|
60
|
+
separatePdfInput
|
|
34
61
|
} from "../internal/grpc_layer/util";
|
|
62
|
+
import fs from "fs";
|
|
63
|
+
import {mergePdfs, renderHtmlToPdf, renderHtmlZipToPdf, renderUrlToPdf} from "../internal/grpc_layer/chrome/render";
|
|
64
|
+
import {disposePdf, getBinaryData, openPdfFileBuffer} from "../internal/grpc_layer/pdfium/io";
|
|
65
|
+
import {Access} from "../internal/access";
|
|
66
|
+
import {renderImagesBufferToPdf, renderImagesFilesToPdf} from "../internal/grpc_layer/chrome/image";
|
|
67
|
+
import {compressImage, compressStructTree} from "../internal/grpc_layer/pdfium/compress";
|
|
68
|
+
import {
|
|
69
|
+
duplicate,
|
|
70
|
+
getPageInfo,
|
|
71
|
+
insertPdf,
|
|
72
|
+
removePage,
|
|
73
|
+
resizePage,
|
|
74
|
+
setPageRotation
|
|
75
|
+
} from "../internal/grpc_layer/pdfium/page";
|
|
76
|
+
import {extractRawImages, rasterizeToImageBuffers} from "../internal/grpc_layer/pdfium/image";
|
|
77
|
+
import Jimp from "jimp";
|
|
78
|
+
import {extractAllText, replaceText} from "../internal/grpc_layer/pdfium/text";
|
|
79
|
+
import {toPdfA, toPdfUA} from "../internal/grpc_layer/pdfium/pdfa";
|
|
80
|
+
import {getMetadataDict, removeMetadata, setMetadata, setMetadataDict} from "../internal/grpc_layer/pdfium/metadata";
|
|
81
|
+
import {getSignatureCount, signPdf} from "../internal/grpc_layer/pdfium/signing";
|
|
82
|
+
import {addHtmlAffix, addTextAffix} from "../internal/grpc_layer/pdfium/headerFooter";
|
|
83
|
+
import {stampBarcode, stampHtml, stampImage, stampText} from "../internal/grpc_layer/chrome/stamp";
|
|
84
|
+
import {addBackgroundForeground} from "../internal/grpc_layer/pdfium/BackgroundForeground";
|
|
85
|
+
import {
|
|
86
|
+
getPermission,
|
|
87
|
+
removePasswordsAndEncryption,
|
|
88
|
+
setOwnerPasswords, setSecurity,
|
|
89
|
+
setUserPasswords
|
|
90
|
+
} from "../internal/grpc_layer/pdfium/security";
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Represents a PDF document. Allows: loading, editing, manipulating, merging, signing printing and saving PDFs.
|
|
94
|
+
*
|
|
95
|
+
* @remark Make sure that you call {@link PdfDocument.close} or {@link cleanUp} to free the memory, when you stop using the PdfDocument object.
|
|
96
|
+
*/
|
|
97
|
+
export class PdfDocument{
|
|
98
|
+
|
|
99
|
+
//#region io
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Open or Create a PdfDocument from a {@link PdfInput}
|
|
103
|
+
* @param pdfInput {@link PdfInput}
|
|
104
|
+
* @param options including {@link PdfPassword} {@link ChromePdfRenderOptions} {@link HttpLoginCredentials} mainHtmlFile
|
|
105
|
+
*/
|
|
106
|
+
public static async open(
|
|
107
|
+
pdfInput: PdfInput,
|
|
108
|
+
options?: {
|
|
109
|
+
/**
|
|
110
|
+
* required for open a protected PDF file
|
|
111
|
+
* @default undefined
|
|
112
|
+
*/
|
|
113
|
+
password?: PdfPassword;
|
|
114
|
+
/**
|
|
115
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
116
|
+
* @default undefined
|
|
117
|
+
*/
|
|
118
|
+
renderOptions?: ChromePdfRenderOptions;
|
|
119
|
+
/**
|
|
120
|
+
* Apply httpLoginCredentials if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
121
|
+
* @default undefined
|
|
122
|
+
*/
|
|
123
|
+
httpLoginCredentials?: HttpLoginCredentials;
|
|
124
|
+
/**
|
|
125
|
+
* Apply mainHtmlFile if PdfInput is {@link ZipFilePath}
|
|
126
|
+
* @default index.html
|
|
127
|
+
*/
|
|
128
|
+
mainHtmlFile?: string;
|
|
129
|
+
/**
|
|
130
|
+
* Optionally track changes to the document (for use with incremental saves)
|
|
131
|
+
* @default {@link ChangeTrackingModes.AutoChangeTracking}
|
|
132
|
+
*/
|
|
133
|
+
trackChanges?: ChangeTrackingModes;
|
|
134
|
+
// /**
|
|
135
|
+
// * Apply baseUrl if
|
|
136
|
+
// * The HTML base URL for which references to external CSS, Javascript and Image files will be relative.
|
|
137
|
+
// * @default undefined
|
|
138
|
+
// */
|
|
139
|
+
// baseUrl?: string; //not supported
|
|
140
|
+
}
|
|
141
|
+
): Promise<PdfDocument> {
|
|
142
|
+
return z.function()
|
|
143
|
+
.args(
|
|
144
|
+
pdfInputSchema,
|
|
145
|
+
z.object({
|
|
146
|
+
password: pdfPasswordSchema.optional(),
|
|
147
|
+
renderOptions: chromePdfRenderOptionsSchema.optional(),
|
|
148
|
+
httpLoginCredentials: httpLoginCredentialsSchema.optional(),
|
|
149
|
+
mainHtmlFile: stringSchema.optional(),
|
|
150
|
+
trackChanges: changeTrackingModesSchema.optional(),
|
|
151
|
+
}).optional()
|
|
152
|
+
)
|
|
153
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
154
|
+
.implement(this.internal_open.bind(this))
|
|
155
|
+
(pdfInput, options);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Open a PdfDocument from .pdf file
|
|
160
|
+
* @param pdfFilePath A path to .pdf file
|
|
161
|
+
* @param Optionally track changes to the document (for use with incremental saves)
|
|
162
|
+
*/
|
|
163
|
+
public static async fromFile(
|
|
164
|
+
pdfFilePath: string, trackChanges?: ChangeTrackingModes
|
|
165
|
+
): Promise<PdfDocument> {
|
|
166
|
+
return z.function()
|
|
167
|
+
.args(
|
|
168
|
+
pdfFilePathSchema,
|
|
169
|
+
changeTrackingModesSchema.optional()
|
|
170
|
+
)
|
|
171
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
172
|
+
.implement(this.internal_fromFile.bind(this))
|
|
173
|
+
(pdfFilePath, trackChanges);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Create a PdfDocument from an Url
|
|
178
|
+
* @param url A website Url
|
|
179
|
+
* @param options including {@link ChromePdfRenderOptions}
|
|
180
|
+
*/
|
|
181
|
+
public static async fromUrl(
|
|
182
|
+
url: URL | string,
|
|
183
|
+
options?: {
|
|
184
|
+
/**
|
|
185
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
186
|
+
* @default undefined
|
|
187
|
+
*/
|
|
188
|
+
renderOptions?: ChromePdfRenderOptions;
|
|
189
|
+
}
|
|
190
|
+
): Promise<PdfDocument> {
|
|
191
|
+
return z.function()
|
|
192
|
+
.args(
|
|
193
|
+
z.union([urlSchema, stringSchema]),
|
|
194
|
+
z.object({
|
|
195
|
+
renderOptions: chromePdfRenderOptionsSchema.optional(),
|
|
196
|
+
}).optional()
|
|
197
|
+
)
|
|
198
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
199
|
+
.implement(this.internal_fromUrl.bind(this))
|
|
200
|
+
(url, options);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Creates a PDF file from a local Zip file, and returns it as a {@link PdfDocument}.
|
|
205
|
+
* IronPDF is a W3C standards compliant HTML rendering based on Google's Chromium browser.
|
|
206
|
+
* If your output PDF does not look as expected:
|
|
207
|
+
*
|
|
208
|
+
* - Validate your HTML file using https://validator.w3.org/ & CSS https://jigsaw.w3.org/css-validator/
|
|
209
|
+
*
|
|
210
|
+
* - To debug HTML, view the file in Chrome web browser's print preview which will work almost exactly as IronPDF.
|
|
211
|
+
*
|
|
212
|
+
* - Read our detailed documentation on pixel perfect HTML to PDF: https://ironpdf.com/tutorials/pixel-perfect-html-to-pdf/
|
|
213
|
+
*
|
|
214
|
+
* @param zipFilePath Path to a Zip to be rendered as a PDF.
|
|
215
|
+
* @param options including {@link ChromePdfRenderOptions} and `mainHtmlFile` a main .html file default: `index.html`
|
|
216
|
+
*/
|
|
217
|
+
public static async fromZip(
|
|
218
|
+
zipFilePath: string,
|
|
219
|
+
options?: {
|
|
220
|
+
/**
|
|
221
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
222
|
+
* @default undefined
|
|
223
|
+
*/
|
|
224
|
+
renderOptions?: ChromePdfRenderOptions;
|
|
225
|
+
/**
|
|
226
|
+
* a main .html file default: `index.html`
|
|
227
|
+
*/
|
|
228
|
+
mainHtmlFile?: string;
|
|
229
|
+
}
|
|
230
|
+
): Promise<PdfDocument> {
|
|
231
|
+
return z.function()
|
|
232
|
+
.args(
|
|
233
|
+
stringSchema,
|
|
234
|
+
z.object({
|
|
235
|
+
renderOptions: chromePdfRenderOptionsSchema.optional(),
|
|
236
|
+
mainHtmlFile: stringSchema.optional()
|
|
237
|
+
}).optional()
|
|
238
|
+
)
|
|
239
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
240
|
+
.implement(this.internal_fromZip.bind(this))
|
|
241
|
+
(zipFilePath, options);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Creates a PDF file from a Html string, and returns it as an {@link PdfDocument} object which can be edited and saved to disk or served on a website.
|
|
246
|
+
* @param htmlStringOrHtmlFilePath The Html to be rendered as a PDF.
|
|
247
|
+
* @param options including {@link ChromePdfRenderOptions}
|
|
248
|
+
*/
|
|
249
|
+
public static async fromHtml(
|
|
250
|
+
htmlStringOrHtmlFilePath: string,
|
|
251
|
+
options?: {
|
|
252
|
+
/**
|
|
253
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
254
|
+
* @default undefined
|
|
255
|
+
*/
|
|
256
|
+
renderOptions?: ChromePdfRenderOptions;
|
|
257
|
+
}
|
|
258
|
+
): Promise<PdfDocument> {
|
|
259
|
+
return z.function()
|
|
260
|
+
.args(
|
|
261
|
+
stringSchema,
|
|
262
|
+
z.object({
|
|
263
|
+
renderOptions: chromePdfRenderOptionsSchema.optional(),
|
|
264
|
+
}).optional()
|
|
265
|
+
)
|
|
266
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
267
|
+
.implement(this.internal_fromHtml.bind(this))
|
|
268
|
+
(htmlStringOrHtmlFilePath, options);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Converts multiple image files to a PDF document. Each image creates 1 page which matches the image
|
|
273
|
+
* dimensions. The default PaperSize is A4. You can set it via ImageToPdfConverter.PaperSize.
|
|
274
|
+
* Note: Imaging.ImageBehavior.CropPage will set PaperSize equal to ImageSize.
|
|
275
|
+
* @param images The image file path name(s) or {@link ImageBuffer} object(s)
|
|
276
|
+
* @param options including {@link ImageToPdfOptions}
|
|
277
|
+
*/
|
|
278
|
+
public static async fromImage(
|
|
279
|
+
images: ImageFilePath | ImageFilePath[] | ImageBuffer | ImageBuffer[],
|
|
280
|
+
options?: {
|
|
281
|
+
/**
|
|
282
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
283
|
+
* @default undefined
|
|
284
|
+
*/
|
|
285
|
+
imageToPdfOptions?: ImageToPdfOptions;
|
|
286
|
+
}
|
|
287
|
+
): Promise<PdfDocument> {
|
|
288
|
+
return z.function()
|
|
289
|
+
.args(
|
|
290
|
+
z.union([imageFilePathSchema, z.array(imageFilePathSchema), imageBufferSchema, z.array(imageBufferSchema)]),
|
|
291
|
+
z.object({
|
|
292
|
+
imageToPdfOptions: imageToPdfOptionsSchema.optional(),
|
|
293
|
+
}).optional()
|
|
294
|
+
)
|
|
295
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
296
|
+
.implement(this.internal_fromImage.bind(this))
|
|
297
|
+
(images, options);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Static method that joins (concatenates) multiple PDF documents together into one compiled PDF document.
|
|
302
|
+
* If the PDF contains form fields the form field in the resulting PDF's name will be appended with '_{index}' e.g. 'Name' will be 'Name_0'
|
|
303
|
+
* @param pdfs array of PDF
|
|
304
|
+
*/
|
|
305
|
+
public static async mergePdf(pdfs: PdfInput[]): Promise<PdfDocument> {
|
|
306
|
+
return z.function()
|
|
307
|
+
.args(
|
|
308
|
+
z.array(pdfInputSchema)
|
|
309
|
+
)
|
|
310
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
311
|
+
.implement(this.internal_mergePdf.bind(this))
|
|
312
|
+
(pdfs);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Saves the PdfDocument to a file.
|
|
317
|
+
* @param filePath Target file path
|
|
318
|
+
* @param saveOptions see {@link SaveOptions}
|
|
319
|
+
*/
|
|
320
|
+
public saveAs(filePath: string, saveOptions?: SaveOptions): Promise<void> {
|
|
321
|
+
return z.function()
|
|
322
|
+
.args(
|
|
323
|
+
stringSchema,
|
|
324
|
+
saveOptionsSchema.optional()
|
|
325
|
+
)
|
|
326
|
+
.returns(z.promise(z.void()))
|
|
327
|
+
.implement(this.internal_saveAs.bind(this))
|
|
328
|
+
(filePath, saveOptions);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Saves the PdfDocument to a binary (Buffer)
|
|
333
|
+
* @param saveOptions see {@link SaveOptions}
|
|
334
|
+
*/
|
|
335
|
+
public async saveAsBuffer(saveOptions?: SaveOptions): Promise<Buffer> {
|
|
336
|
+
return z.function()
|
|
337
|
+
.args(
|
|
338
|
+
saveOptionsSchema.optional()
|
|
339
|
+
)
|
|
340
|
+
.returns(z.promise(bufferSchema))
|
|
341
|
+
.implement(this.internal_saveAsBuffer.bind(this))
|
|
342
|
+
(saveOptions);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
//#endregion
|
|
346
|
+
|
|
347
|
+
//#region compress
|
|
348
|
+
/**
|
|
349
|
+
* Compress existing PDF images using JPG encoding and the specified settings
|
|
350
|
+
* @param imageQuality Quality (1 - 100) to use during compression
|
|
351
|
+
* @param scaleToVisibleSize Scale down the image resolution according to its visible size in the PDF document
|
|
352
|
+
*/
|
|
353
|
+
public async compressSize(
|
|
354
|
+
imageQuality: number,
|
|
355
|
+
scaleToVisibleSize = false
|
|
356
|
+
): Promise<void> {
|
|
357
|
+
return await z.function()
|
|
358
|
+
.args(
|
|
359
|
+
numberSchema,
|
|
360
|
+
booleanSchema.optional()
|
|
361
|
+
)
|
|
362
|
+
.returns(z.promise(z.void()))
|
|
363
|
+
.implement(this.internal_compressSize.bind(this))
|
|
364
|
+
(imageQuality, scaleToVisibleSize);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Remove document struct tree information which describes the logical layout of the document.
|
|
369
|
+
* Removing the "structure tree" can significantly reduce the disk space used by the document.
|
|
370
|
+
* Removing the "structure tree" of a complicated document can negatively impact text selection.
|
|
371
|
+
*/
|
|
372
|
+
public async compressStructTree(): Promise<void> {
|
|
373
|
+
return this.internal_compressStructTree()
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
//#endregion
|
|
377
|
+
|
|
378
|
+
//#region page
|
|
379
|
+
/**
|
|
380
|
+
* Gets information of all pages in the PdfDocument
|
|
381
|
+
*/
|
|
382
|
+
public async getPagesInfo(): Promise<PageInfo[]> {
|
|
383
|
+
return this.internal_getPagesInfo()
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Gets the number of pages in the PdfDocument.
|
|
388
|
+
*/
|
|
389
|
+
public async getPageCount(): Promise<number> {
|
|
390
|
+
return this.internal_getPageCount()
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Set the page orientation.
|
|
395
|
+
* @param pageRotation see {@link PageRotation}
|
|
396
|
+
* @param options including {@link PdfPageSelection}
|
|
397
|
+
*/
|
|
398
|
+
public async setRotation(
|
|
399
|
+
pageRotation: PageRotation,
|
|
400
|
+
options?: {
|
|
401
|
+
/**
|
|
402
|
+
* @default "all"
|
|
403
|
+
*/
|
|
404
|
+
pdfPageSelection?: PdfPageSelection;
|
|
405
|
+
}
|
|
406
|
+
) {
|
|
407
|
+
return z.function()
|
|
408
|
+
.args(
|
|
409
|
+
pageRotationSchema,
|
|
410
|
+
z.object({pdfPageSelection: pdfPageSelectionSchema.optional()}).optional()
|
|
411
|
+
)
|
|
412
|
+
.returns(z.promise(z.void()))
|
|
413
|
+
.implement(this.internal_setRotation.bind(this))
|
|
414
|
+
(pageRotation, options);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Resize a page to the specified dimensions
|
|
419
|
+
* @param newSize {@link PdfPaperSize}
|
|
420
|
+
* @param options including {@link PdfPageSelection}
|
|
421
|
+
*/
|
|
422
|
+
public async resize(
|
|
423
|
+
newSize: PdfPaperSize,
|
|
424
|
+
options?: {
|
|
425
|
+
/**
|
|
426
|
+
* @default "all"
|
|
427
|
+
*/
|
|
428
|
+
pdfPageSelection?: PdfPageSelection;
|
|
429
|
+
}
|
|
430
|
+
): Promise<void> {
|
|
431
|
+
return z.function()
|
|
432
|
+
.args(
|
|
433
|
+
pdfPaperSizeSchema,
|
|
434
|
+
z.object({pdfPageSelection: pdfPageSelectionSchema.optional()}).optional()
|
|
435
|
+
)
|
|
436
|
+
.returns(z.promise(z.void()))
|
|
437
|
+
.implement(this.internal_resize.bind(this))
|
|
438
|
+
(newSize, options);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Adds another PDF to the beginning of the current PdfDocument
|
|
443
|
+
* If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will be 'Name_'
|
|
444
|
+
* @param fromPdfDocument PdfDocument to prepend
|
|
445
|
+
*/
|
|
446
|
+
public async prependAnotherPdf(
|
|
447
|
+
fromPdfDocument: PdfDocument
|
|
448
|
+
): Promise<void> {
|
|
449
|
+
return z.function()
|
|
450
|
+
.args(pdfDocumentSchema)
|
|
451
|
+
.returns(z.promise(z.void()))
|
|
452
|
+
.implement(this.internal_prependAnotherPdf.bind(this))
|
|
453
|
+
(fromPdfDocument);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Appends another PDF to the end of the current <see cref="PdfDocument"/>
|
|
458
|
+
* If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will be 'Name_'
|
|
459
|
+
* @param fromPdfDocument PdfDocument to Append
|
|
460
|
+
*/
|
|
461
|
+
public async appendAnotherPdf(fromPdfDocument: PdfDocument): Promise<void> {
|
|
462
|
+
return z.function()
|
|
463
|
+
.args(pdfDocumentSchema)
|
|
464
|
+
.returns(z.promise(z.void()))
|
|
465
|
+
.implement(this.internal_appendAnotherPdf.bind(this))
|
|
466
|
+
(fromPdfDocument);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Inserts another PDF into the current PdfDocument, starting at a given Page Index.
|
|
471
|
+
* If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will be 'Name_'
|
|
472
|
+
* @param fromPdfDocument Another PdfDocument
|
|
473
|
+
* @param insertAtPageIndex Index at which to insert the new content. Note: Page 1 has index 0...
|
|
474
|
+
*/
|
|
475
|
+
public async insertPagesFromAnotherPdf(
|
|
476
|
+
fromPdfDocument: PdfDocument,
|
|
477
|
+
insertAtPageIndex: number
|
|
478
|
+
): Promise<void> {
|
|
479
|
+
return z.function()
|
|
480
|
+
.args(pdfDocumentSchema, numberSchema.describe("insertAtPageIndex: number"))
|
|
481
|
+
.returns(z.promise(z.void()))
|
|
482
|
+
.implement(this.internal_insertPagesFromAnotherPdf.bind(this))
|
|
483
|
+
(fromPdfDocument, insertAtPageIndex);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Removes a range of pages from the PDF
|
|
488
|
+
* @param pages pages to remove
|
|
489
|
+
*/
|
|
490
|
+
public async removePage(pages: PdfPageSelection): Promise<void> {
|
|
491
|
+
return z.function()
|
|
492
|
+
.args(pdfPageSelectionSchema)
|
|
493
|
+
.returns(z.promise(z.void()))
|
|
494
|
+
.implement(this.internal_removePage.bind(this))
|
|
495
|
+
(pages);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Creates a new PDF by copying a range of pages from this {@link PdfDocument}.
|
|
500
|
+
* @param pages pages to copy (default "all")
|
|
501
|
+
*/
|
|
502
|
+
public async duplicate(
|
|
503
|
+
pages: PdfPageSelection = "all"
|
|
504
|
+
): Promise<PdfDocument> {
|
|
505
|
+
return z.function()
|
|
506
|
+
.args(pdfPageSelectionSchema)
|
|
507
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
508
|
+
.implement(this.internal_duplicate.bind(this))
|
|
509
|
+
(pages);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
//#endregion
|
|
513
|
+
|
|
514
|
+
//#region image
|
|
515
|
+
/**
|
|
516
|
+
* Finds all embedded Images from within a specified pages in the PDF and returns them as Buffer
|
|
517
|
+
* @param options including {@link PdfPageSelection}
|
|
518
|
+
*/
|
|
519
|
+
public async extractRawImages(options?: {
|
|
520
|
+
/**
|
|
521
|
+
* @default "all"
|
|
522
|
+
*/
|
|
523
|
+
fromPages?: PdfPageSelection;
|
|
524
|
+
}): Promise<Buffer[]> {
|
|
525
|
+
return z.function()
|
|
526
|
+
.args(
|
|
527
|
+
z.object({fromPages: pdfPageSelectionSchema.optional()}).optional()
|
|
528
|
+
)
|
|
529
|
+
.returns(z.promise(bufferArraySchema))
|
|
530
|
+
.implement(this.internal_extractRawImages.bind(this))
|
|
531
|
+
(options);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Renders the PDF and exports image Files in convenient formats. 1 image file is created for each
|
|
536
|
+
* page.
|
|
537
|
+
*
|
|
538
|
+
* @param options including {@link PdfPageSelection} {@link ImageType}
|
|
539
|
+
*
|
|
540
|
+
* @return array of images as Buffer[]
|
|
541
|
+
*/
|
|
542
|
+
public async rasterizeToImageBuffers(options?: {
|
|
543
|
+
/**
|
|
544
|
+
* @default "all"
|
|
545
|
+
*/
|
|
546
|
+
fromPages?: PdfPageSelection;
|
|
547
|
+
/**
|
|
548
|
+
* @default {@link ImageType.PNG}
|
|
549
|
+
*/
|
|
550
|
+
imageType?: ImageType;
|
|
551
|
+
}): Promise<Buffer[]> {
|
|
552
|
+
return z.function()
|
|
553
|
+
.args(
|
|
554
|
+
z.object({
|
|
555
|
+
fromPages: pdfPageSelectionSchema.optional(),
|
|
556
|
+
imageType: imageTypeSchema.optional()
|
|
557
|
+
}).optional()
|
|
558
|
+
)
|
|
559
|
+
.returns(z.promise(bufferArraySchema))
|
|
560
|
+
.implement(this.internal_rasterizeToImageBuffers.bind(this))
|
|
561
|
+
(options);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Renders the PDF and exports image Files in convenient formats. 1 image file is created for each
|
|
566
|
+
* page. Running number will append output file path.
|
|
567
|
+
*
|
|
568
|
+
* @param filePath output file path.
|
|
569
|
+
* @param options including {@link PdfPageSelection} {@link ImageType}
|
|
570
|
+
*
|
|
571
|
+
* @return array of images file name as string[]
|
|
572
|
+
*/
|
|
573
|
+
public async rasterizeToImageFiles(
|
|
574
|
+
filePath: string,
|
|
575
|
+
options?: {
|
|
576
|
+
/**
|
|
577
|
+
* @default "all"
|
|
578
|
+
*/
|
|
579
|
+
fromPages?: PdfPageSelection;
|
|
580
|
+
/**
|
|
581
|
+
* @default {@link ImageType.PNG}
|
|
582
|
+
*/
|
|
583
|
+
type?: ImageType;
|
|
584
|
+
}
|
|
585
|
+
): Promise<string[]> {
|
|
586
|
+
return z.function()
|
|
587
|
+
.args(
|
|
588
|
+
filePathSchema,
|
|
589
|
+
z.object({
|
|
590
|
+
fromPages: pdfPageSelectionSchema.optional(),
|
|
591
|
+
type: imageTypeSchema.optional()
|
|
592
|
+
}).optional()
|
|
593
|
+
)
|
|
594
|
+
.returns(z.promise(stringArraySchema))
|
|
595
|
+
.implement(this.internal_rasterizeToImageFiles.bind(this))
|
|
596
|
+
(filePath, options);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
//#endregion
|
|
600
|
+
|
|
601
|
+
//#region text
|
|
602
|
+
/**
|
|
603
|
+
* Replace the specified old text with new text on a given page
|
|
604
|
+
* @param oldText Old text to remove
|
|
605
|
+
* @param newText New text to add
|
|
606
|
+
* @param onPages Page index to search for old text to replace (default "all")
|
|
607
|
+
*/
|
|
608
|
+
public async replaceText(
|
|
609
|
+
oldText: string,
|
|
610
|
+
newText: string,
|
|
611
|
+
onPages?: PdfPageSelection
|
|
612
|
+
): Promise<void> {
|
|
613
|
+
return z.function()
|
|
614
|
+
.args(
|
|
615
|
+
z.string({description: "oldText: string"}),
|
|
616
|
+
z.string({description: "newText: string"}),
|
|
617
|
+
pdfPageSelectionSchema.optional())
|
|
618
|
+
.returns(z.promise(z.void()))
|
|
619
|
+
.implement(this.internal_replaceText.bind(this))
|
|
620
|
+
(oldText, newText, onPages);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
public async extractText(
|
|
624
|
+
onPages?: PdfPageSelection
|
|
625
|
+
): Promise<string> {
|
|
626
|
+
return z.function()
|
|
627
|
+
.args(pdfPageSelectionSchema.optional())
|
|
628
|
+
.returns(z.promise(z.string()))
|
|
629
|
+
.implement(this.internal_extractText.bind(this))
|
|
630
|
+
(onPages);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
//#endregion
|
|
634
|
+
|
|
635
|
+
//#region pdfA
|
|
636
|
+
/**
|
|
637
|
+
* Convert the current document into the specified PDF-A standard format
|
|
638
|
+
* @param customICC (Optional) Custom color profile file path
|
|
639
|
+
*/
|
|
640
|
+
public async convertToPdfA(customICC?: string): Promise<void> {
|
|
641
|
+
return z.function()
|
|
642
|
+
.args(z.string({description: "customICC: string"}).optional())
|
|
643
|
+
.returns(z.promise(z.void()))
|
|
644
|
+
.implement(this.internal_convertToPdfA.bind(this))
|
|
645
|
+
(customICC);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Convert the current document into the specified PDF/UA standard format
|
|
650
|
+
*/
|
|
651
|
+
public async convertToPdfUA(): Promise<void> {
|
|
652
|
+
return this.internal_convertToPdfUA()
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
//#endregion
|
|
656
|
+
|
|
657
|
+
//#region metadata
|
|
658
|
+
/**
|
|
659
|
+
* Gets a Map<string, string> of metadata properties
|
|
660
|
+
*/
|
|
661
|
+
public async getMetadata(): Promise<Map<string, string>> {
|
|
662
|
+
return this.internal_getMetadata()
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Add or Update a single metadata property
|
|
667
|
+
* @param key
|
|
668
|
+
* @param value
|
|
669
|
+
*/
|
|
670
|
+
public async addOrUpdateMetadata(
|
|
671
|
+
key: string,
|
|
672
|
+
value: string
|
|
673
|
+
): Promise<void> {
|
|
674
|
+
return z.function()
|
|
675
|
+
.args(z.string({description: "key: string"}), z.string({description: "value: string"}))
|
|
676
|
+
.returns(z.promise(z.void()))
|
|
677
|
+
.implement(this.internal_addOrUpdateMetadata.bind(this))
|
|
678
|
+
(key, value);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Remove a single metadata property
|
|
683
|
+
* @param key
|
|
684
|
+
*/
|
|
685
|
+
public async removeMetadata(key: string): Promise<void> {
|
|
686
|
+
return z.function()
|
|
687
|
+
.args(z.string({description: "key: string"}))
|
|
688
|
+
.returns(z.promise(z.void()))
|
|
689
|
+
.implement(this.internal_removeMetadata.bind(this))
|
|
690
|
+
(key);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Sets a whole metadata properties Map<string, string> (override all the metadata property)
|
|
695
|
+
* @param newMetadataDictionary new metadata properties Map<string, string>
|
|
696
|
+
*/
|
|
697
|
+
public async overrideMetadata(
|
|
698
|
+
newMetadataDictionary: Map<string, string>
|
|
699
|
+
): Promise<void> {
|
|
700
|
+
return z.function()
|
|
701
|
+
.args(mapStringSchema)
|
|
702
|
+
.returns(z.promise(z.void()))
|
|
703
|
+
.implement(this.internal_overrideMetadata.bind(this))
|
|
704
|
+
(newMetadataDictionary);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
//#endregion
|
|
708
|
+
|
|
709
|
+
//#region signing
|
|
710
|
+
/**
|
|
711
|
+
* Sign PDF with digital signature certificate.
|
|
712
|
+
* Note that the PDF will not be fully signed until Saved
|
|
713
|
+
* using {@link saveAs} or {@link saveAsBuffer}
|
|
714
|
+
*
|
|
715
|
+
* Multiple certificates may be used.
|
|
716
|
+
* @param signature see {@link DigitalSignature}
|
|
717
|
+
*/
|
|
718
|
+
public async signDigitalSignature(signature: DigitalSignature) {
|
|
719
|
+
return z.function()
|
|
720
|
+
.args(digitalSignatureSchema)
|
|
721
|
+
.returns(z.promise(z.void()))
|
|
722
|
+
.implement(this.internal_signDigitalSignature.bind(this))
|
|
723
|
+
(signature);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Check if PdfDocument was signed or not
|
|
728
|
+
*/
|
|
729
|
+
public async isSigned(): Promise<boolean> {
|
|
730
|
+
return this.internal_isSigned()
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Count the number signature that signed to this PdfDocument
|
|
735
|
+
*/
|
|
736
|
+
public async signatureCount(): Promise<number> {
|
|
737
|
+
return this.internal_signatureCount()
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
//#endregion
|
|
741
|
+
|
|
742
|
+
//#region header/footer (affix)
|
|
743
|
+
/**
|
|
744
|
+
* Apply page header on top of an existing Pdf.
|
|
745
|
+
* @param header {@link TextAffix}
|
|
746
|
+
* @param toPages {@link PdfPageSelection}
|
|
747
|
+
*/
|
|
748
|
+
public async addTextHeader(
|
|
749
|
+
header: TextAffix,
|
|
750
|
+
toPages?: PdfPageSelection
|
|
751
|
+
): Promise<void> {
|
|
752
|
+
return z.function()
|
|
753
|
+
.args(textAffixSchema, pdfPageSelectionSchema.optional())
|
|
754
|
+
.returns(z.promise(z.void()))
|
|
755
|
+
.implement(this.internal_addTextHeader.bind(this))
|
|
756
|
+
(header, toPages);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Apply page footer on top of an existing Pdf.
|
|
761
|
+
* @param footer {@link TextAffix}
|
|
762
|
+
* @param toPages {@link PdfPageSelection}
|
|
763
|
+
*/
|
|
764
|
+
public async addTextFooter(
|
|
765
|
+
footer: TextAffix,
|
|
766
|
+
toPages?: PdfPageSelection
|
|
767
|
+
): Promise<void> {
|
|
768
|
+
return z.function()
|
|
769
|
+
.args(textAffixSchema, pdfPageSelectionSchema.optional())
|
|
770
|
+
.returns(z.promise(z.void()))
|
|
771
|
+
.implement(this.internal_addTextFooter.bind(this))
|
|
772
|
+
(footer, toPages);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Apply HTML header on top of an existing Pdf.
|
|
777
|
+
* @param header {@link HtmlAffix}
|
|
778
|
+
* @param toPages {@link PdfPageSelection}
|
|
779
|
+
*/
|
|
780
|
+
public async addHtmlHeader(
|
|
781
|
+
header: HtmlAffix,
|
|
782
|
+
toPages?: PdfPageSelection
|
|
783
|
+
): Promise<void> {
|
|
784
|
+
return z.function()
|
|
785
|
+
.args(htmlAffixSchema, pdfPageSelectionSchema.optional())
|
|
786
|
+
.returns(z.promise(z.void()))
|
|
787
|
+
.implement(this.internal_addHtmlHeader.bind(this))
|
|
788
|
+
(header, toPages);
|
|
789
|
+
}
|
|
35
790
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
791
|
+
/**
|
|
792
|
+
* Apply HTML footer on top of an existing Pdf.
|
|
793
|
+
* @param footer {@link HtmlAffix}
|
|
794
|
+
* @param toPages {@link PdfPageSelection}
|
|
795
|
+
*/
|
|
796
|
+
public async addHtmlFooter(
|
|
797
|
+
footer: HtmlAffix,
|
|
798
|
+
toPages?: PdfPageSelection
|
|
799
|
+
): Promise<void> {
|
|
800
|
+
return z.function()
|
|
801
|
+
.args(htmlAffixSchema, pdfPageSelectionSchema.optional())
|
|
802
|
+
.returns(z.promise(z.void()))
|
|
803
|
+
.implement(this.internal_addHtmlFooter.bind(this))
|
|
804
|
+
(footer, toPages);
|
|
805
|
+
}
|
|
47
806
|
|
|
48
|
-
|
|
49
|
-
renderImagesBufferToPdf,
|
|
50
|
-
renderImagesFilesToPdf,
|
|
51
|
-
} from "../internal/grpc_layer/chrome/image";
|
|
52
|
-
import {
|
|
53
|
-
extractRawImages,
|
|
54
|
-
rasterizeToImageBuffers,
|
|
55
|
-
} from "../internal/grpc_layer/pdfium/image";
|
|
807
|
+
//#endregion
|
|
56
808
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
import {toPdfA, toPdfUA} from "../internal/grpc_layer/pdfium/pdfa";
|
|
80
|
-
import {compressImage, compressStructTree} from "../internal/grpc_layer/pdfium/compress";
|
|
81
|
-
import {
|
|
82
|
-
getSignatureCount,
|
|
83
|
-
signPdf,
|
|
84
|
-
} from "../internal/grpc_layer/pdfium/signing";
|
|
85
|
-
import {
|
|
86
|
-
addHtmlAffix,
|
|
87
|
-
addTextAffix,
|
|
88
|
-
} from "../internal/grpc_layer/pdfium/headerFooter";
|
|
89
|
-
import {addBackgroundForeground} from "../internal/grpc_layer/pdfium/BackgroundForeground";
|
|
90
|
-
import {extractAllText, replaceText} from "../internal/grpc_layer/pdfium/text";
|
|
91
|
-
import {
|
|
92
|
-
getMetadataDict,
|
|
93
|
-
removeMetadata,
|
|
94
|
-
setMetadata,
|
|
95
|
-
setMetadataDict,
|
|
96
|
-
} from "../internal/grpc_layer/pdfium/metadata";
|
|
97
|
-
import {Access} from "../internal/access";
|
|
809
|
+
//#region stamp
|
|
810
|
+
/**
|
|
811
|
+
* Edits the PDF by applying the HTML's rendered to only selected page(s).
|
|
812
|
+
* @param htmlStringOrHtmlFilePath
|
|
813
|
+
* @param options including {@link HtmlStampOptions} {@link PdfPageSelection}
|
|
814
|
+
*/
|
|
815
|
+
public async stampHtml(
|
|
816
|
+
htmlStringOrHtmlFilePath: HtmlFilePath | HtmlString,
|
|
817
|
+
options?: {
|
|
818
|
+
htmlStampOptions?: HtmlStampOptions;
|
|
819
|
+
toPages?: PdfPageSelection;
|
|
820
|
+
}
|
|
821
|
+
) {
|
|
822
|
+
return z.function()
|
|
823
|
+
.args(z.union([htmlFilePathSchema, htmlStringSchema]), z.object({
|
|
824
|
+
htmlStampOptions: htmlStampOptionsSchema.optional(),
|
|
825
|
+
toPages: pdfPageSelectionSchema.optional()
|
|
826
|
+
}).optional())
|
|
827
|
+
.returns(z.promise(z.void()))
|
|
828
|
+
.implement(this.internal_stampHtml.bind(this))
|
|
829
|
+
(htmlStringOrHtmlFilePath, options);
|
|
830
|
+
}
|
|
98
831
|
|
|
99
|
-
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
832
|
+
/**
|
|
833
|
+
* Edits the PDF by applying the image to only selected page(s).
|
|
834
|
+
* @param image image file path or image buffer
|
|
835
|
+
* @param options including {@link ImageStampOptions} {@link PdfPageSelection}
|
|
836
|
+
*/
|
|
837
|
+
public async stampImage(
|
|
838
|
+
image: ImageFilePath | ImageBuffer,
|
|
839
|
+
options?: {
|
|
840
|
+
imageStampOptions?: ImageStampOptions;
|
|
841
|
+
toPages?: PdfPageSelection;
|
|
842
|
+
}
|
|
843
|
+
) {
|
|
844
|
+
return z.function()
|
|
845
|
+
.args(z.union([imageFilePathSchema, imageBufferSchema]), z.object({
|
|
846
|
+
imageStampOptions: imageStampOptionsSchema.optional(),
|
|
847
|
+
toPages: pdfPageSelectionSchema.optional()
|
|
848
|
+
}).optional())
|
|
849
|
+
.returns(z.promise(z.void()))
|
|
850
|
+
.implement(this.internal_stampImage.bind(this))
|
|
851
|
+
(image, options);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* Edits the PDF by applying the text to only selected page(s).
|
|
856
|
+
* @param text text to stamp
|
|
857
|
+
* @param options including {@link TextStampOptions} {@link PdfPageSelection}
|
|
858
|
+
*/
|
|
859
|
+
public async stampText(
|
|
860
|
+
text: string,
|
|
861
|
+
options?: {
|
|
862
|
+
textStampOptions?: TextStampOptions;
|
|
863
|
+
toPages?: PdfPageSelection;
|
|
864
|
+
}
|
|
865
|
+
) {
|
|
866
|
+
return z.function()
|
|
867
|
+
.args(stringSchema, z.object({
|
|
868
|
+
textStampOptions: textStampOptionsSchema.optional(),
|
|
869
|
+
toPages: pdfPageSelectionSchema.optional()
|
|
870
|
+
}).optional())
|
|
871
|
+
.returns(z.promise(z.void()))
|
|
872
|
+
.implement(this.internal_stampText.bind(this))
|
|
873
|
+
(text, options);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* Edits the PDF by applying the barcode to only selected page(s).
|
|
878
|
+
* @param barcodeValue barcode
|
|
879
|
+
* @param options including {@link BarcodeType} {@link BarcodeStampOptions} {@link PdfPageSelection}
|
|
880
|
+
*/
|
|
881
|
+
public async stampBarcode(
|
|
882
|
+
barcodeValue: string,
|
|
883
|
+
options?: {
|
|
884
|
+
barcodeEncoding: BarcodeType;
|
|
885
|
+
barcodeStampOptions?: BarcodeStampOptions;
|
|
886
|
+
toPages?: PdfPageSelection;
|
|
887
|
+
}
|
|
888
|
+
) {
|
|
889
|
+
return z.function()
|
|
890
|
+
.args(stringSchema, z.object({
|
|
891
|
+
barcodeEncoding: barcodeTypeSchema,
|
|
892
|
+
barcodeStampOptions: barcodeStampOptionsSchema.optional(),
|
|
893
|
+
toPages: pdfPageSelectionSchema.optional()
|
|
894
|
+
}).optional())
|
|
895
|
+
.returns(z.promise(z.void()))
|
|
896
|
+
.implement(this.internal_stampBarcode.bind(this))
|
|
897
|
+
(barcodeValue, options);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
//#endregion
|
|
901
|
+
|
|
902
|
+
//#region background/foreground
|
|
903
|
+
/**
|
|
904
|
+
* Adds a background to each page of this PDF. The background is copied from a first page in the
|
|
905
|
+
* backgroundPdf document.
|
|
906
|
+
*
|
|
907
|
+
* @param fromPdf background PDF document
|
|
908
|
+
* @param sourcePageIndex Index (zero-based page number) of the page to copy from the Background/Foreground PDF. Default is 0.
|
|
909
|
+
* @param applyToPages PageSelection to which the background/foreground will be added. Default is "all"
|
|
910
|
+
*/
|
|
911
|
+
public async addBackgroundFromAnotherPdf(
|
|
912
|
+
fromPdf: PdfDocument,
|
|
913
|
+
sourcePageIndex = 0,
|
|
914
|
+
applyToPages?: PdfPageSelection
|
|
915
|
+
): Promise<void> {
|
|
916
|
+
return z.function()
|
|
917
|
+
.args(pdfDocumentSchema, numberSchema, pdfPageSelectionSchema.optional())
|
|
918
|
+
.returns(z.promise(z.void()))
|
|
919
|
+
.implement(this.internal_addBackgroundFromAnotherPdf.bind(this))
|
|
920
|
+
(fromPdf, sourcePageIndex, applyToPages);
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* Adds a foreground to each page of this PDF. The background is copied from a first page in the
|
|
925
|
+
* backgroundPdf document.
|
|
926
|
+
*
|
|
927
|
+
* @param fromPdf foreground PDF document
|
|
928
|
+
* @param sourcePageIndex Index (zero-based page number) of the page to copy from the Background/Foreground PDF. Default is 0.
|
|
929
|
+
* @param applyToPages PageSelection to which the background/foreground will be added. Default is "all"
|
|
930
|
+
*/
|
|
931
|
+
public async addForegroundFromAnotherPdf(
|
|
932
|
+
fromPdf: PdfDocument,
|
|
933
|
+
sourcePageIndex = 0,
|
|
934
|
+
applyToPages?: PdfPageSelection
|
|
935
|
+
): Promise<void> {
|
|
936
|
+
return z.function()
|
|
937
|
+
.args(pdfDocumentSchema, numberSchema, pdfPageSelectionSchema.optional())
|
|
938
|
+
.returns(z.promise(z.void()))
|
|
939
|
+
.implement(this.internal_addForegroundFromAnotherPdf.bind(this))
|
|
940
|
+
(fromPdf, sourcePageIndex, applyToPages);
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
//#endregion
|
|
944
|
+
|
|
945
|
+
//#region security
|
|
946
|
+
/**
|
|
947
|
+
* Removes all user and owner password security for a PDF document. Also disables content
|
|
948
|
+
* encryption.
|
|
949
|
+
* If content is encrypted at 128 bit, copy and paste of content, annotations and form editing may be disabled.
|
|
950
|
+
*/
|
|
951
|
+
public async removePasswordsAndEncryption(): Promise<void> {
|
|
952
|
+
return this.internal_removePasswordsAndEncryption()
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/**
|
|
956
|
+
* Sets the user password and enables 128Bit encryption of PDF content.
|
|
957
|
+
* A user password is a password that each user must enter to open or print the PDF document.
|
|
958
|
+
*/
|
|
959
|
+
public async setUserPassword(userPassword: string): Promise<void> {
|
|
960
|
+
return z.function()
|
|
961
|
+
.args(z.string({description: "userPassword: string"}))
|
|
962
|
+
.returns(z.promise(z.void()))
|
|
963
|
+
.implement(this.internal_setUserPassword.bind(this))
|
|
964
|
+
(userPassword);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* Sets the owner password and enables 128Bit encryption of PDF content. An owner password is one used to
|
|
969
|
+
* enable and disable all other security settings. <para>OwnerPassword must be set to a non-empty string
|
|
970
|
+
* value for {@link PdfPermission.AllowAccessibilityExtractContent} , {@link PdfPermission.AllowAnnotations} ,
|
|
971
|
+
* {@link PdfPermission.AllowFillForms}, {@link PdfPermission.AllowPrint}, {@link PdfPermission.AllowModify} to be
|
|
972
|
+
* restricted.
|
|
973
|
+
*/
|
|
974
|
+
public async setOwnerPassword(ownerPassword: string): Promise<void> {
|
|
975
|
+
return z.function()
|
|
976
|
+
.args(z.string({description: "ownerPassword: string"}))
|
|
977
|
+
.returns(z.promise(z.void()))
|
|
978
|
+
.implement(this.internal_setOwnerPassword.bind(this))
|
|
979
|
+
(ownerPassword);
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* Sets the permissions of this PdfDocument
|
|
984
|
+
* @param permissions see {@link PdfPermission}
|
|
985
|
+
*/
|
|
986
|
+
public async setPermission(permissions: PdfPermission): Promise<void> {
|
|
987
|
+
return z.function()
|
|
988
|
+
.args(pdfPermissionSchema)
|
|
989
|
+
.returns(z.promise(z.void()))
|
|
990
|
+
.implement(this.internal_setPermission.bind(this))
|
|
991
|
+
(permissions);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
/**
|
|
995
|
+
* Gets the current permissions of this PdfDocument
|
|
996
|
+
* @return {@link PdfPermission}
|
|
997
|
+
*/
|
|
998
|
+
public async getPermission(): Promise<PdfPermission> {
|
|
999
|
+
return this.internal_getPermission()
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Makes this PDF document read only such that: Content is encrypted at 128 bit. Copy and paste of
|
|
1004
|
+
* content is disallowed. Annotations and form editing are disabled.
|
|
1005
|
+
* @param ownerPassword The owner password for the PDF. A string for owner password is required to enable PDF encryption and
|
|
1006
|
+
* all document security options.
|
|
1007
|
+
*/
|
|
1008
|
+
public async makePdfDocumentReadOnly(ownerPassword: string): Promise<void> {
|
|
1009
|
+
return z.function()
|
|
1010
|
+
.args(z.string({description: "ownerPassword: string"}))
|
|
1011
|
+
.returns(z.promise(z.void()))
|
|
1012
|
+
.implement(this.internal_makePdfDocumentReadOnly.bind(this))
|
|
1013
|
+
(ownerPassword);
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
//#endregion
|
|
1017
|
+
|
|
1018
|
+
//#region close
|
|
1019
|
+
/**
|
|
1020
|
+
* Dispose this PdfDocument object (clean up the resource)
|
|
1021
|
+
* This is necessary to free the memory used by PdfDocument. See {@link cleanUp}
|
|
1022
|
+
* Once this method was called this PdfDocument object no longer usable.
|
|
1023
|
+
*/
|
|
1024
|
+
public async close() {
|
|
1025
|
+
return this.internal_close()
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
//#endregion
|
|
1029
|
+
|
|
1030
|
+
//#region ALL_INTERNAL_STUFF
|
|
105
1031
|
/**
|
|
106
1032
|
* Internal PDF document ID
|
|
107
1033
|
* @private
|
|
@@ -118,16 +1044,15 @@ export class PdfDocument {
|
|
|
118
1044
|
|
|
119
1045
|
/**
|
|
120
1046
|
* Create a PdfDocument object from a {@link PdfInput}
|
|
121
|
-
* For more specific way to create/open
|
|
1047
|
+
* For more specific way to create/open PdfDocument see {@link fromUrl} {@link fromZip} {@link fromHtml} {@link fromImage} {@link open}
|
|
122
1048
|
*
|
|
123
1049
|
* @param pdfInput see {@link PdfInput} (required)
|
|
124
|
-
* @param password a password to open the PDF required if PDF file was
|
|
1050
|
+
* @param password a password to open the PDF required if PDF file was private (pdfInput is {@link PdfFilePath} or {@link Buffer})
|
|
125
1051
|
* @param trackChanges Optionally track changes to the document (for use with incremental saves)
|
|
126
1052
|
*/
|
|
127
1053
|
constructor(pdfInput?: PdfInput, password?: PdfPassword, trackChanges?: ChangeTrackingModes) {
|
|
128
1054
|
if (pdfInput) {
|
|
129
1055
|
this.pdfDocumentId = undefined;
|
|
130
|
-
|
|
131
1056
|
const input = separatePdfInput(pdfInput);
|
|
132
1057
|
switch (input.type) {
|
|
133
1058
|
case "htmlFile":
|
|
@@ -178,19 +1103,19 @@ export class PdfDocument {
|
|
|
178
1103
|
* This is necessary to free the memory used by PdfDocument. See {@link cleanUp}
|
|
179
1104
|
* Once this method was called this PdfDocument object no longer usable.
|
|
180
1105
|
*/
|
|
181
|
-
|
|
182
|
-
await disposePdf(await this.
|
|
1106
|
+
private async internal_close() {
|
|
1107
|
+
await disposePdf(await this.internal_getId());
|
|
183
1108
|
}
|
|
184
1109
|
|
|
185
1110
|
/**
|
|
186
1111
|
* @private
|
|
187
1112
|
*/
|
|
188
|
-
private async
|
|
1113
|
+
private async internal_getId(): Promise<string> {
|
|
189
1114
|
if (this.pdfDocumentId) {
|
|
190
|
-
return this.pdfDocumentId;
|
|
1115
|
+
return Promise.resolve(this.pdfDocumentId) ;
|
|
191
1116
|
} else if (this.promiseDocumentId) {
|
|
192
1117
|
this.pdfDocumentId = await this.promiseDocumentId;
|
|
193
|
-
return this.pdfDocumentId;
|
|
1118
|
+
return Promise.resolve(this.pdfDocumentId);
|
|
194
1119
|
} else {
|
|
195
1120
|
throw new Error("Cannot Get PdfDocumentId");
|
|
196
1121
|
}
|
|
@@ -203,27 +1128,27 @@ export class PdfDocument {
|
|
|
203
1128
|
* @param pdfInput {@link PdfInput}
|
|
204
1129
|
* @param options including {@link PdfPassword} {@link ChromePdfRenderOptions} {@link HttpLoginCredentials} mainHtmlFile
|
|
205
1130
|
*/
|
|
206
|
-
|
|
1131
|
+
private static async internal_open(
|
|
207
1132
|
pdfInput: PdfInput,
|
|
208
1133
|
options?: {
|
|
209
1134
|
/**
|
|
210
|
-
* required for open a
|
|
211
|
-
* @default
|
|
1135
|
+
* required for open a private PDF file
|
|
1136
|
+
* @default undefined
|
|
212
1137
|
*/
|
|
213
1138
|
password?: PdfPassword;
|
|
214
1139
|
/**
|
|
215
1140
|
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
216
|
-
* @default
|
|
1141
|
+
* @default undefined
|
|
217
1142
|
*/
|
|
218
1143
|
renderOptions?: ChromePdfRenderOptions;
|
|
219
1144
|
/**
|
|
220
1145
|
* Apply httpLoginCredentials if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
221
|
-
* @default
|
|
1146
|
+
* @default undefined
|
|
222
1147
|
*/
|
|
223
1148
|
httpLoginCredentials?: HttpLoginCredentials;
|
|
224
1149
|
/**
|
|
225
1150
|
* Apply mainHtmlFile if PdfInput is {@link ZipFilePath}
|
|
226
|
-
* @default
|
|
1151
|
+
* @default index.html
|
|
227
1152
|
*/
|
|
228
1153
|
mainHtmlFile?: string;
|
|
229
1154
|
/**
|
|
@@ -234,7 +1159,7 @@ export class PdfDocument {
|
|
|
234
1159
|
// /**
|
|
235
1160
|
// * Apply baseUrl if
|
|
236
1161
|
// * The HTML base URL for which references to external CSS, Javascript and Image files will be relative.
|
|
237
|
-
// * @default
|
|
1162
|
+
// * @default undefined
|
|
238
1163
|
// */
|
|
239
1164
|
// baseUrl?: string; //not supported
|
|
240
1165
|
}
|
|
@@ -315,10 +1240,10 @@ export class PdfDocument {
|
|
|
315
1240
|
* @param pdfFilePath A path to .pdf file
|
|
316
1241
|
* @param Optionally track changes to the document (for use with incremental saves)
|
|
317
1242
|
*/
|
|
318
|
-
|
|
1243
|
+
private static async internal_fromFile(
|
|
319
1244
|
pdfFilePath: string, trackChanges?: ChangeTrackingModes
|
|
320
1245
|
): Promise<PdfDocument> {
|
|
321
|
-
return this.
|
|
1246
|
+
return this.internal_open(pdfFilePath, {trackChanges: trackChanges});
|
|
322
1247
|
}
|
|
323
1248
|
|
|
324
1249
|
/**
|
|
@@ -326,17 +1251,17 @@ export class PdfDocument {
|
|
|
326
1251
|
* @param url A website Url
|
|
327
1252
|
* @param options including {@link ChromePdfRenderOptions}
|
|
328
1253
|
*/
|
|
329
|
-
|
|
1254
|
+
private static async internal_fromUrl(
|
|
330
1255
|
url: URL | string,
|
|
331
1256
|
options?: {
|
|
332
1257
|
/**
|
|
333
1258
|
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
334
|
-
* @default
|
|
1259
|
+
* @default undefined
|
|
335
1260
|
*/
|
|
336
1261
|
renderOptions?: ChromePdfRenderOptions;
|
|
337
1262
|
}
|
|
338
1263
|
): Promise<PdfDocument> {
|
|
339
|
-
return this.
|
|
1264
|
+
return this.internal_open(url, options);
|
|
340
1265
|
}
|
|
341
1266
|
|
|
342
1267
|
/**
|
|
@@ -353,12 +1278,12 @@ export class PdfDocument {
|
|
|
353
1278
|
* @param zipFilePath Path to a Zip to be rendered as a PDF.
|
|
354
1279
|
* @param options including {@link ChromePdfRenderOptions} and `mainHtmlFile` a main .html file default: `index.html`
|
|
355
1280
|
*/
|
|
356
|
-
|
|
1281
|
+
private static async internal_fromZip(
|
|
357
1282
|
zipFilePath: string,
|
|
358
1283
|
options?: {
|
|
359
1284
|
/**
|
|
360
1285
|
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
361
|
-
* @default
|
|
1286
|
+
* @default undefined
|
|
362
1287
|
*/
|
|
363
1288
|
renderOptions?: ChromePdfRenderOptions;
|
|
364
1289
|
/**
|
|
@@ -367,7 +1292,7 @@ export class PdfDocument {
|
|
|
367
1292
|
mainHtmlFile?: string;
|
|
368
1293
|
}
|
|
369
1294
|
): Promise<PdfDocument> {
|
|
370
|
-
return this.
|
|
1295
|
+
return this.internal_open(zipFilePath, options);
|
|
371
1296
|
}
|
|
372
1297
|
|
|
373
1298
|
/**
|
|
@@ -375,17 +1300,17 @@ export class PdfDocument {
|
|
|
375
1300
|
* @param htmlStringOrHtmlFilePath The Html to be rendered as a PDF.
|
|
376
1301
|
* @param options including {@link ChromePdfRenderOptions}
|
|
377
1302
|
*/
|
|
378
|
-
|
|
1303
|
+
private static async internal_fromHtml(
|
|
379
1304
|
htmlStringOrHtmlFilePath: string,
|
|
380
1305
|
options?: {
|
|
381
1306
|
/**
|
|
382
1307
|
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
383
|
-
* @default
|
|
1308
|
+
* @default undefined
|
|
384
1309
|
*/
|
|
385
1310
|
renderOptions?: ChromePdfRenderOptions;
|
|
386
1311
|
}
|
|
387
1312
|
): Promise<PdfDocument> {
|
|
388
|
-
return this.
|
|
1313
|
+
return this.internal_open(htmlStringOrHtmlFilePath, options);
|
|
389
1314
|
}
|
|
390
1315
|
|
|
391
1316
|
/**
|
|
@@ -395,12 +1320,12 @@ export class PdfDocument {
|
|
|
395
1320
|
* @param images The image file path name(s) or {@link ImageBuffer} object(s)
|
|
396
1321
|
* @param options including {@link ImageToPdfOptions}
|
|
397
1322
|
*/
|
|
398
|
-
|
|
1323
|
+
private static async internal_fromImage(
|
|
399
1324
|
images: ImageFilePath | ImageFilePath[] | ImageBuffer | ImageBuffer[],
|
|
400
1325
|
options?: {
|
|
401
1326
|
/**
|
|
402
1327
|
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
403
|
-
* @default
|
|
1328
|
+
* @default undefined
|
|
404
1329
|
*/
|
|
405
1330
|
imageToPdfOptions?: ImageToPdfOptions;
|
|
406
1331
|
}
|
|
@@ -461,9 +1386,9 @@ export class PdfDocument {
|
|
|
461
1386
|
* If the PDF contains form fields the form field in the resulting PDF's name will be appended with '_{index}' e.g. 'Name' will be 'Name_0'
|
|
462
1387
|
* @param pdfs array of PDF
|
|
463
1388
|
*/
|
|
464
|
-
|
|
1389
|
+
private static async internal_mergePdf(pdfs: PdfInput[]): Promise<PdfDocument> {
|
|
465
1390
|
const ids = await Promise.all(
|
|
466
|
-
pdfs.map(async (x) => (await PdfDocument.open(x)).
|
|
1391
|
+
pdfs.map(async (x) => (await PdfDocument.open(x)).internal_getId())
|
|
467
1392
|
);
|
|
468
1393
|
const newDocId = mergePdfs(ids);
|
|
469
1394
|
const newUrlPdf = new PdfDocument();
|
|
@@ -476,8 +1401,8 @@ export class PdfDocument {
|
|
|
476
1401
|
* @param filePath Target file path
|
|
477
1402
|
* @param saveOptions see {@link SaveOptions}
|
|
478
1403
|
*/
|
|
479
|
-
|
|
480
|
-
return this.
|
|
1404
|
+
private async internal_saveAs(filePath: string, saveOptions?: SaveOptions): Promise<void> {
|
|
1405
|
+
return this.internal_saveAsBuffer(saveOptions).then((pdfFileBuffer) => {
|
|
481
1406
|
fs.writeFile(filePath, pdfFileBuffer, "binary", (err) => {
|
|
482
1407
|
if (err) throw err;
|
|
483
1408
|
});
|
|
@@ -488,8 +1413,8 @@ export class PdfDocument {
|
|
|
488
1413
|
* Saves the PdfDocument to a binary (Buffer)
|
|
489
1414
|
* @param saveOptions see {@link SaveOptions}
|
|
490
1415
|
*/
|
|
491
|
-
|
|
492
|
-
return getBinaryData(await this.
|
|
1416
|
+
private async internal_saveAsBuffer(saveOptions?: SaveOptions): Promise<Buffer> {
|
|
1417
|
+
return getBinaryData(await this.internal_getId(), saveOptions);
|
|
493
1418
|
}
|
|
494
1419
|
|
|
495
1420
|
//#endregion
|
|
@@ -500,7 +1425,7 @@ export class PdfDocument {
|
|
|
500
1425
|
* @param imageQuality Quality (1 - 100) to use during compression
|
|
501
1426
|
* @param scaleToVisibleSize Scale down the image resolution according to its visible size in the PDF document
|
|
502
1427
|
*/
|
|
503
|
-
|
|
1428
|
+
private async internal_compressSize(
|
|
504
1429
|
imageQuality: number,
|
|
505
1430
|
scaleToVisibleSize = false
|
|
506
1431
|
): Promise<void> {
|
|
@@ -509,7 +1434,7 @@ export class PdfDocument {
|
|
|
509
1434
|
`Invalid quality specifier (${imageQuality}) when compressing images. Quality must be between 1 and 100.`
|
|
510
1435
|
);
|
|
511
1436
|
return await compressImage(
|
|
512
|
-
await this.
|
|
1437
|
+
await this.internal_getId(),
|
|
513
1438
|
imageQuality,
|
|
514
1439
|
scaleToVisibleSize
|
|
515
1440
|
);
|
|
@@ -520,8 +1445,8 @@ export class PdfDocument {
|
|
|
520
1445
|
* Removing the "structure tree" can significantly reduce the disk space used by the document.
|
|
521
1446
|
* Removing the "structure tree" of a complicated document can negatively impact text selection.
|
|
522
1447
|
*/
|
|
523
|
-
|
|
524
|
-
return await compressStructTree(await this.
|
|
1448
|
+
private async internal_compressStructTree(): Promise<void> {
|
|
1449
|
+
return await compressStructTree(await this.internal_getId());
|
|
525
1450
|
}
|
|
526
1451
|
|
|
527
1452
|
//#endregion
|
|
@@ -530,15 +1455,15 @@ export class PdfDocument {
|
|
|
530
1455
|
/**
|
|
531
1456
|
* Gets information of all pages in the PdfDocument
|
|
532
1457
|
*/
|
|
533
|
-
|
|
534
|
-
return await getPageInfo(await this.
|
|
1458
|
+
private async internal_getPagesInfo(): Promise<PageInfo[]> {
|
|
1459
|
+
return await getPageInfo(await this.internal_getId());
|
|
535
1460
|
}
|
|
536
1461
|
|
|
537
1462
|
/**
|
|
538
1463
|
* Gets the number of pages in the PdfDocument.
|
|
539
1464
|
*/
|
|
540
|
-
|
|
541
|
-
return (await this.
|
|
1465
|
+
private async internal_getPageCount(): Promise<number> {
|
|
1466
|
+
return (await this.internal_getPagesInfo()).length;
|
|
542
1467
|
}
|
|
543
1468
|
|
|
544
1469
|
/**
|
|
@@ -546,7 +1471,7 @@ export class PdfDocument {
|
|
|
546
1471
|
* @param pageRotation see {@link PageRotation}
|
|
547
1472
|
* @param options including {@link PdfPageSelection}
|
|
548
1473
|
*/
|
|
549
|
-
|
|
1474
|
+
private async internal_setRotation(
|
|
550
1475
|
pageRotation: PageRotation,
|
|
551
1476
|
options?: {
|
|
552
1477
|
/**
|
|
@@ -555,7 +1480,7 @@ export class PdfDocument {
|
|
|
555
1480
|
pdfPageSelection?: PdfPageSelection;
|
|
556
1481
|
}
|
|
557
1482
|
) {
|
|
558
|
-
return await setPageRotation(await this.
|
|
1483
|
+
return await setPageRotation(await this.internal_getId(), pageRotation, options);
|
|
559
1484
|
}
|
|
560
1485
|
|
|
561
1486
|
/**
|
|
@@ -563,16 +1488,16 @@ export class PdfDocument {
|
|
|
563
1488
|
* @param newSize {@link PdfPaperSize}
|
|
564
1489
|
* @param options including {@link PdfPageSelection}
|
|
565
1490
|
*/
|
|
566
|
-
|
|
1491
|
+
private async internal_resize(
|
|
567
1492
|
newSize: PdfPaperSize,
|
|
568
1493
|
options?: {
|
|
569
1494
|
/**
|
|
570
1495
|
* @default "all"
|
|
571
1496
|
*/
|
|
572
|
-
|
|
1497
|
+
pdfPageSelection?: PdfPageSelection;
|
|
573
1498
|
}
|
|
574
1499
|
): Promise<void> {
|
|
575
|
-
return await resizePage(await this.
|
|
1500
|
+
return await resizePage(await this.internal_getId(), newSize, options);
|
|
576
1501
|
}
|
|
577
1502
|
|
|
578
1503
|
/**
|
|
@@ -580,10 +1505,10 @@ export class PdfDocument {
|
|
|
580
1505
|
* If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will be 'Name_'
|
|
581
1506
|
* @param fromPdfDocument PdfDocument to prepend
|
|
582
1507
|
*/
|
|
583
|
-
|
|
1508
|
+
private async internal_prependAnotherPdf(
|
|
584
1509
|
fromPdfDocument: PdfDocument
|
|
585
1510
|
): Promise<void> {
|
|
586
|
-
await this.
|
|
1511
|
+
await this.internal_insertPagesFromAnotherPdf(fromPdfDocument, 0);
|
|
587
1512
|
}
|
|
588
1513
|
|
|
589
1514
|
/**
|
|
@@ -591,10 +1516,10 @@ export class PdfDocument {
|
|
|
591
1516
|
* If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will be 'Name_'
|
|
592
1517
|
* @param fromPdfDocument PdfDocument to Append
|
|
593
1518
|
*/
|
|
594
|
-
|
|
595
|
-
await this.
|
|
1519
|
+
private async internal_appendAnotherPdf(fromPdfDocument: PdfDocument): Promise<void> {
|
|
1520
|
+
await this.internal_insertPagesFromAnotherPdf(
|
|
596
1521
|
fromPdfDocument,
|
|
597
|
-
(await this.
|
|
1522
|
+
(await this.internal_getPageCount()) - 1
|
|
598
1523
|
);
|
|
599
1524
|
}
|
|
600
1525
|
|
|
@@ -604,13 +1529,13 @@ export class PdfDocument {
|
|
|
604
1529
|
* @param fromPdfDocument Another PdfDocument
|
|
605
1530
|
* @param insertAtPageIndex Index at which to insert the new content. Note: Page 1 has index 0...
|
|
606
1531
|
*/
|
|
607
|
-
|
|
1532
|
+
private async internal_insertPagesFromAnotherPdf(
|
|
608
1533
|
fromPdfDocument: PdfDocument,
|
|
609
1534
|
insertAtPageIndex: number
|
|
610
1535
|
): Promise<void> {
|
|
611
1536
|
await insertPdf(
|
|
612
|
-
await this.
|
|
613
|
-
await fromPdfDocument.
|
|
1537
|
+
await this.internal_getId(),
|
|
1538
|
+
await fromPdfDocument.internal_getId(),
|
|
614
1539
|
insertAtPageIndex
|
|
615
1540
|
);
|
|
616
1541
|
}
|
|
@@ -619,19 +1544,19 @@ export class PdfDocument {
|
|
|
619
1544
|
* Removes a range of pages from the PDF
|
|
620
1545
|
* @param pages pages to remove
|
|
621
1546
|
*/
|
|
622
|
-
|
|
623
|
-
await removePage(await this.
|
|
1547
|
+
private async internal_removePage(pages: PdfPageSelection): Promise<void> {
|
|
1548
|
+
await removePage(await this.internal_getId(), {PdfPageSelection: pages});
|
|
624
1549
|
}
|
|
625
1550
|
|
|
626
1551
|
/**
|
|
627
1552
|
* Creates a new PDF by copying a range of pages from this {@link PdfDocument}.
|
|
628
1553
|
* @param pages pages to copy (default "all")
|
|
629
1554
|
*/
|
|
630
|
-
|
|
1555
|
+
private async internal_duplicate(
|
|
631
1556
|
pages: PdfPageSelection = "all"
|
|
632
1557
|
): Promise<PdfDocument> {
|
|
633
1558
|
const newPdf = new PdfDocument();
|
|
634
|
-
newPdf.pdfDocumentId = await duplicate(await this.
|
|
1559
|
+
newPdf.pdfDocumentId = await duplicate(await this.internal_getId(), {
|
|
635
1560
|
PdfPageSelection: pages,
|
|
636
1561
|
});
|
|
637
1562
|
return newPdf;
|
|
@@ -644,14 +1569,14 @@ export class PdfDocument {
|
|
|
644
1569
|
* Finds all embedded Images from within a specified pages in the PDF and returns them as Buffer
|
|
645
1570
|
* @param options including {@link PdfPageSelection}
|
|
646
1571
|
*/
|
|
647
|
-
|
|
1572
|
+
private async internal_extractRawImages(options?: {
|
|
648
1573
|
/**
|
|
649
1574
|
* @default "all"
|
|
650
1575
|
*/
|
|
651
|
-
fromPages
|
|
1576
|
+
fromPages?: PdfPageSelection;
|
|
652
1577
|
}): Promise<Buffer[]> {
|
|
653
1578
|
return extractRawImages(
|
|
654
|
-
await this.
|
|
1579
|
+
await this.internal_getId(),
|
|
655
1580
|
options?.fromPages ?? "all"
|
|
656
1581
|
);
|
|
657
1582
|
}
|
|
@@ -664,18 +1589,18 @@ export class PdfDocument {
|
|
|
664
1589
|
*
|
|
665
1590
|
* @return array of images as Buffer[]
|
|
666
1591
|
*/
|
|
667
|
-
|
|
1592
|
+
private async internal_rasterizeToImageBuffers(options?: {
|
|
668
1593
|
/**
|
|
669
1594
|
* @default "all"
|
|
670
1595
|
*/
|
|
671
|
-
fromPages
|
|
1596
|
+
fromPages?: PdfPageSelection;
|
|
672
1597
|
/**
|
|
673
1598
|
* @default {@link ImageType.PNG}
|
|
674
1599
|
*/
|
|
675
1600
|
imageType?: ImageType;
|
|
676
1601
|
}): Promise<Buffer[]> {
|
|
677
1602
|
const images = await rasterizeToImageBuffers(
|
|
678
|
-
await this.
|
|
1603
|
+
await this.internal_getId(),
|
|
679
1604
|
options?.fromPages ?? "all"
|
|
680
1605
|
);
|
|
681
1606
|
const jimpImageType: "image/bmp" | "image/png" | "image/jpeg" = (() => {
|
|
@@ -708,7 +1633,7 @@ export class PdfDocument {
|
|
|
708
1633
|
*
|
|
709
1634
|
* @return array of images file name as string[]
|
|
710
1635
|
*/
|
|
711
|
-
|
|
1636
|
+
private async internal_rasterizeToImageFiles(
|
|
712
1637
|
filePath: string,
|
|
713
1638
|
options?: {
|
|
714
1639
|
/**
|
|
@@ -722,7 +1647,7 @@ export class PdfDocument {
|
|
|
722
1647
|
}
|
|
723
1648
|
): Promise<string[]> {
|
|
724
1649
|
const images = await rasterizeToImageBuffers(
|
|
725
|
-
await this.
|
|
1650
|
+
await this.internal_getId(),
|
|
726
1651
|
options?.fromPages ?? "all"
|
|
727
1652
|
);
|
|
728
1653
|
const filesName = getFileNames(
|
|
@@ -751,18 +1676,18 @@ export class PdfDocument {
|
|
|
751
1676
|
* @param newText New text to add
|
|
752
1677
|
* @param onPages Page index to search for old text to replace (default "all")
|
|
753
1678
|
*/
|
|
754
|
-
|
|
1679
|
+
private async internal_replaceText(
|
|
755
1680
|
oldText: string,
|
|
756
1681
|
newText: string,
|
|
757
1682
|
onPages?: PdfPageSelection
|
|
758
1683
|
): Promise<void> {
|
|
759
|
-
return replaceText(await this.
|
|
1684
|
+
return replaceText(await this.internal_getId(), oldText, newText, onPages);
|
|
760
1685
|
}
|
|
761
1686
|
|
|
762
|
-
|
|
1687
|
+
private async internal_extractText(
|
|
763
1688
|
onPages?: PdfPageSelection
|
|
764
1689
|
): Promise<string> {
|
|
765
|
-
return extractAllText(await this.
|
|
1690
|
+
return extractAllText(await this.internal_getId(), onPages);
|
|
766
1691
|
}
|
|
767
1692
|
|
|
768
1693
|
//#endregion
|
|
@@ -772,15 +1697,15 @@ export class PdfDocument {
|
|
|
772
1697
|
* Convert the current document into the specified PDF-A standard format
|
|
773
1698
|
* @param customICC (Optional) Custom color profile file path
|
|
774
1699
|
*/
|
|
775
|
-
|
|
776
|
-
return await toPdfA(await this.
|
|
1700
|
+
private async internal_convertToPdfA(customICC?: string): Promise<void> {
|
|
1701
|
+
return await toPdfA(await this.internal_getId(), customICC);
|
|
777
1702
|
}
|
|
778
1703
|
|
|
779
1704
|
/**
|
|
780
1705
|
* Convert the current document into the specified PDF/UA standard format
|
|
781
1706
|
*/
|
|
782
|
-
|
|
783
|
-
return await toPdfUA(await this.
|
|
1707
|
+
private async internal_convertToPdfUA(): Promise<void> {
|
|
1708
|
+
return await toPdfUA(await this.internal_getId());
|
|
784
1709
|
}
|
|
785
1710
|
|
|
786
1711
|
//#endregion
|
|
@@ -789,8 +1714,8 @@ export class PdfDocument {
|
|
|
789
1714
|
/**
|
|
790
1715
|
* Gets a Map<string, string> of metadata properties
|
|
791
1716
|
*/
|
|
792
|
-
|
|
793
|
-
return getMetadataDict(await this.
|
|
1717
|
+
private async internal_getMetadata(): Promise<Map<string, string>> {
|
|
1718
|
+
return getMetadataDict(await this.internal_getId());
|
|
794
1719
|
}
|
|
795
1720
|
|
|
796
1721
|
/**
|
|
@@ -798,29 +1723,30 @@ export class PdfDocument {
|
|
|
798
1723
|
* @param key
|
|
799
1724
|
* @param value
|
|
800
1725
|
*/
|
|
801
|
-
|
|
1726
|
+
private async internal_addOrUpdateMetadata(
|
|
802
1727
|
key: string,
|
|
803
1728
|
value: string
|
|
804
1729
|
): Promise<void> {
|
|
805
|
-
return setMetadata(await this.
|
|
1730
|
+
return setMetadata(await this.internal_getId(), key, value);
|
|
806
1731
|
}
|
|
807
1732
|
|
|
808
1733
|
/**
|
|
809
1734
|
* Remove a single metadata property
|
|
810
1735
|
* @param key
|
|
811
1736
|
*/
|
|
812
|
-
|
|
813
|
-
return removeMetadata(await this.
|
|
1737
|
+
private async internal_removeMetadata(key: string): Promise<void> {
|
|
1738
|
+
return removeMetadata(await this.internal_getId(), key);
|
|
814
1739
|
}
|
|
815
1740
|
|
|
1741
|
+
|
|
816
1742
|
/**
|
|
817
1743
|
* Sets a whole metadata properties Map<string, string> (override all the metadata property)
|
|
818
1744
|
* @param newMetadataDictionary new metadata properties Map<string, string>
|
|
819
1745
|
*/
|
|
820
|
-
|
|
1746
|
+
private async internal_overrideMetadata(
|
|
821
1747
|
newMetadataDictionary: Map<string, string>
|
|
822
1748
|
): Promise<void> {
|
|
823
|
-
return setMetadataDict(await this.
|
|
1749
|
+
return setMetadataDict(await this.internal_getId(), newMetadataDictionary);
|
|
824
1750
|
}
|
|
825
1751
|
|
|
826
1752
|
//#endregion
|
|
@@ -834,23 +1760,23 @@ export class PdfDocument {
|
|
|
834
1760
|
* Multiple certificates may be used.
|
|
835
1761
|
* @param signature see {@link DigitalSignature}
|
|
836
1762
|
*/
|
|
837
|
-
|
|
838
|
-
return await signPdf(await this.
|
|
1763
|
+
private async internal_signDigitalSignature(signature: DigitalSignature) {
|
|
1764
|
+
return await signPdf(await this.internal_getId(), signature);
|
|
839
1765
|
}
|
|
840
1766
|
|
|
841
1767
|
/**
|
|
842
1768
|
* Check if PdfDocument was signed or not
|
|
843
1769
|
*/
|
|
844
|
-
|
|
845
|
-
const signatureCount = await getSignatureCount(await this.
|
|
1770
|
+
private async internal_isSigned(): Promise<boolean> {
|
|
1771
|
+
const signatureCount = await getSignatureCount(await this.internal_getId());
|
|
846
1772
|
return signatureCount > 0;
|
|
847
1773
|
}
|
|
848
1774
|
|
|
849
1775
|
/**
|
|
850
1776
|
* Count the number signature that signed to this PdfDocument
|
|
851
1777
|
*/
|
|
852
|
-
|
|
853
|
-
return await getSignatureCount(await this.
|
|
1778
|
+
private async internal_signatureCount(): Promise<number> {
|
|
1779
|
+
return await getSignatureCount(await this.internal_getId());
|
|
854
1780
|
}
|
|
855
1781
|
|
|
856
1782
|
//#endregion
|
|
@@ -861,11 +1787,11 @@ export class PdfDocument {
|
|
|
861
1787
|
* @param header {@link TextAffix}
|
|
862
1788
|
* @param toPages {@link PdfPageSelection}
|
|
863
1789
|
*/
|
|
864
|
-
|
|
1790
|
+
private async internal_addTextHeader(
|
|
865
1791
|
header: TextAffix,
|
|
866
1792
|
toPages?: PdfPageSelection
|
|
867
1793
|
): Promise<void> {
|
|
868
|
-
await addTextAffix(await this.
|
|
1794
|
+
await addTextAffix(await this.internal_getId(), toPages, header, true);
|
|
869
1795
|
}
|
|
870
1796
|
|
|
871
1797
|
/**
|
|
@@ -873,11 +1799,11 @@ export class PdfDocument {
|
|
|
873
1799
|
* @param footer {@link TextAffix}
|
|
874
1800
|
* @param toPages {@link PdfPageSelection}
|
|
875
1801
|
*/
|
|
876
|
-
|
|
1802
|
+
private async internal_addTextFooter(
|
|
877
1803
|
footer: TextAffix,
|
|
878
1804
|
toPages?: PdfPageSelection
|
|
879
1805
|
): Promise<void> {
|
|
880
|
-
await addTextAffix(await this.
|
|
1806
|
+
await addTextAffix(await this.internal_getId(), toPages, footer, false);
|
|
881
1807
|
}
|
|
882
1808
|
|
|
883
1809
|
/**
|
|
@@ -885,11 +1811,11 @@ export class PdfDocument {
|
|
|
885
1811
|
* @param header {@link HtmlAffix}
|
|
886
1812
|
* @param toPages {@link PdfPageSelection}
|
|
887
1813
|
*/
|
|
888
|
-
|
|
1814
|
+
private async internal_addHtmlHeader(
|
|
889
1815
|
header: HtmlAffix,
|
|
890
1816
|
toPages?: PdfPageSelection
|
|
891
1817
|
): Promise<void> {
|
|
892
|
-
await addHtmlAffix(await this.
|
|
1818
|
+
await addHtmlAffix(await this.internal_getId(), toPages, header, true);
|
|
893
1819
|
}
|
|
894
1820
|
|
|
895
1821
|
/**
|
|
@@ -897,11 +1823,11 @@ export class PdfDocument {
|
|
|
897
1823
|
* @param footer {@link HtmlAffix}
|
|
898
1824
|
* @param toPages {@link PdfPageSelection}
|
|
899
1825
|
*/
|
|
900
|
-
|
|
1826
|
+
private async internal_addHtmlFooter(
|
|
901
1827
|
footer: HtmlAffix,
|
|
902
1828
|
toPages?: PdfPageSelection
|
|
903
1829
|
): Promise<void> {
|
|
904
|
-
await addHtmlAffix(await this.
|
|
1830
|
+
await addHtmlAffix(await this.internal_getId(), toPages, footer, false);
|
|
905
1831
|
}
|
|
906
1832
|
|
|
907
1833
|
//#endregion
|
|
@@ -912,7 +1838,7 @@ export class PdfDocument {
|
|
|
912
1838
|
* @param htmlStringOrHtmlFilePath
|
|
913
1839
|
* @param options including {@link HtmlStampOptions} {@link PdfPageSelection}
|
|
914
1840
|
*/
|
|
915
|
-
|
|
1841
|
+
private async internal_stampHtml(
|
|
916
1842
|
htmlStringOrHtmlFilePath: HtmlFilePath | HtmlString,
|
|
917
1843
|
options?: {
|
|
918
1844
|
htmlStampOptions?: HtmlStampOptions;
|
|
@@ -925,7 +1851,7 @@ export class PdfDocument {
|
|
|
925
1851
|
? fs.readFileSync(htmlStringOrHtmlFilePath).toString()
|
|
926
1852
|
: htmlStringOrHtmlFilePath;
|
|
927
1853
|
|
|
928
|
-
await stampHtml(await this.
|
|
1854
|
+
await stampHtml(await this.internal_getId(), html, {
|
|
929
1855
|
password: this.pdfPassword,
|
|
930
1856
|
htmlStampOptions: options?.htmlStampOptions,
|
|
931
1857
|
pageSelection: options?.toPages,
|
|
@@ -937,7 +1863,7 @@ export class PdfDocument {
|
|
|
937
1863
|
* @param image image file path or image buffer
|
|
938
1864
|
* @param options including {@link ImageStampOptions} {@link PdfPageSelection}
|
|
939
1865
|
*/
|
|
940
|
-
|
|
1866
|
+
private async internal_stampImage(
|
|
941
1867
|
image: ImageFilePath | ImageBuffer,
|
|
942
1868
|
options?: {
|
|
943
1869
|
imageStampOptions?: ImageStampOptions;
|
|
@@ -947,9 +1873,9 @@ export class PdfDocument {
|
|
|
947
1873
|
const imageBuffer =
|
|
948
1874
|
image instanceof Buffer ? image : fs.readFileSync(image);
|
|
949
1875
|
|
|
950
|
-
await stampImage(await this.
|
|
1876
|
+
await stampImage(await this.internal_getId(), imageBuffer, {
|
|
951
1877
|
password: this.pdfPassword,
|
|
952
|
-
|
|
1878
|
+
imageStampOptions: options?.imageStampOptions,
|
|
953
1879
|
pageSelection: options?.toPages,
|
|
954
1880
|
});
|
|
955
1881
|
}
|
|
@@ -959,16 +1885,16 @@ export class PdfDocument {
|
|
|
959
1885
|
* @param text text to stamp
|
|
960
1886
|
* @param options including {@link TextStampOptions} {@link PdfPageSelection}
|
|
961
1887
|
*/
|
|
962
|
-
|
|
1888
|
+
private async internal_stampText(
|
|
963
1889
|
text: string,
|
|
964
1890
|
options?: {
|
|
965
1891
|
textStampOptions?: TextStampOptions;
|
|
966
1892
|
toPages?: PdfPageSelection;
|
|
967
1893
|
}
|
|
968
1894
|
) {
|
|
969
|
-
await stampText(await this.
|
|
1895
|
+
await stampText(await this.internal_getId(), text, {
|
|
970
1896
|
password: this.pdfPassword,
|
|
971
|
-
|
|
1897
|
+
textStampOptions: options?.textStampOptions,
|
|
972
1898
|
pageSelection: options?.toPages,
|
|
973
1899
|
});
|
|
974
1900
|
}
|
|
@@ -978,7 +1904,7 @@ export class PdfDocument {
|
|
|
978
1904
|
* @param barcodeValue barcode
|
|
979
1905
|
* @param options including {@link BarcodeType} {@link BarcodeStampOptions} {@link PdfPageSelection}
|
|
980
1906
|
*/
|
|
981
|
-
|
|
1907
|
+
private async internal_stampBarcode(
|
|
982
1908
|
barcodeValue: string,
|
|
983
1909
|
options?: {
|
|
984
1910
|
barcodeEncoding: BarcodeType;
|
|
@@ -987,11 +1913,11 @@ export class PdfDocument {
|
|
|
987
1913
|
}
|
|
988
1914
|
) {
|
|
989
1915
|
await stampBarcode(
|
|
990
|
-
await this.
|
|
1916
|
+
await this.internal_getId(),
|
|
991
1917
|
barcodeValue,
|
|
992
1918
|
{
|
|
993
1919
|
password: this.pdfPassword,
|
|
994
|
-
|
|
1920
|
+
barcodeStampOptions: options?.barcodeStampOptions,
|
|
995
1921
|
pageSelection: options?.toPages,
|
|
996
1922
|
}
|
|
997
1923
|
);
|
|
@@ -1008,14 +1934,14 @@ export class PdfDocument {
|
|
|
1008
1934
|
* @param sourcePageIndex Index (zero-based page number) of the page to copy from the Background/Foreground PDF. Default is 0.
|
|
1009
1935
|
* @param applyToPages PageSelection to which the background/foreground will be added. Default is "all"
|
|
1010
1936
|
*/
|
|
1011
|
-
|
|
1937
|
+
private async internal_addBackgroundFromAnotherPdf(
|
|
1012
1938
|
fromPdf: PdfDocument,
|
|
1013
1939
|
sourcePageIndex = 0,
|
|
1014
1940
|
applyToPages?: PdfPageSelection
|
|
1015
1941
|
): Promise<void> {
|
|
1016
1942
|
return await addBackgroundForeground(
|
|
1017
|
-
await this.
|
|
1018
|
-
await fromPdf.
|
|
1943
|
+
await this.internal_getId(),
|
|
1944
|
+
await fromPdf.internal_getId(),
|
|
1019
1945
|
sourcePageIndex,
|
|
1020
1946
|
true,
|
|
1021
1947
|
applyToPages
|
|
@@ -1030,14 +1956,14 @@ export class PdfDocument {
|
|
|
1030
1956
|
* @param sourcePageIndex Index (zero-based page number) of the page to copy from the Background/Foreground PDF. Default is 0.
|
|
1031
1957
|
* @param applyToPages PageSelection to which the background/foreground will be added. Default is "all"
|
|
1032
1958
|
*/
|
|
1033
|
-
|
|
1959
|
+
private async internal_addForegroundFromAnotherPdf(
|
|
1034
1960
|
fromPdf: PdfDocument,
|
|
1035
1961
|
sourcePageIndex = 0,
|
|
1036
1962
|
applyToPages?: PdfPageSelection
|
|
1037
1963
|
): Promise<void> {
|
|
1038
1964
|
return await addBackgroundForeground(
|
|
1039
|
-
await this.
|
|
1040
|
-
await fromPdf.
|
|
1965
|
+
await this.internal_getId(),
|
|
1966
|
+
await fromPdf.internal_getId(),
|
|
1041
1967
|
sourcePageIndex,
|
|
1042
1968
|
false,
|
|
1043
1969
|
applyToPages
|
|
@@ -1052,20 +1978,20 @@ export class PdfDocument {
|
|
|
1052
1978
|
* encryption.
|
|
1053
1979
|
* If content is encrypted at 128 bit, copy and paste of content, annotations and form editing may be disabled.
|
|
1054
1980
|
*/
|
|
1055
|
-
|
|
1056
|
-
await removePasswordsAndEncryption(await this.
|
|
1981
|
+
private async internal_removePasswordsAndEncryption(): Promise<void> {
|
|
1982
|
+
await removePasswordsAndEncryption(await this.internal_getId());
|
|
1057
1983
|
}
|
|
1058
1984
|
|
|
1059
1985
|
/**
|
|
1060
1986
|
* Sets the user password and enables 128Bit encryption of PDF content.
|
|
1061
1987
|
* A user password is a password that each user must enter to open or print the PDF document.
|
|
1062
1988
|
*/
|
|
1063
|
-
|
|
1989
|
+
private async internal_setUserPassword(userPassword: string): Promise<void> {
|
|
1064
1990
|
if (!this.pdfPassword)
|
|
1065
1991
|
this.pdfPassword = {userPassword: userPassword};
|
|
1066
1992
|
else this.pdfPassword.userPassword = userPassword;
|
|
1067
1993
|
this.pdfDocumentId = await setUserPasswords(
|
|
1068
|
-
await this.
|
|
1994
|
+
await this.internal_getId(),
|
|
1069
1995
|
userPassword
|
|
1070
1996
|
);
|
|
1071
1997
|
}
|
|
@@ -1077,12 +2003,12 @@ export class PdfDocument {
|
|
|
1077
2003
|
* {@link PdfPermission.AllowFillForms}, {@link PdfPermission.AllowPrint}, {@link PdfPermission.AllowModify} to be
|
|
1078
2004
|
* restricted.
|
|
1079
2005
|
*/
|
|
1080
|
-
|
|
2006
|
+
private async internal_setOwnerPassword(ownerPassword: string): Promise<void> {
|
|
1081
2007
|
if (!this.pdfPassword)
|
|
1082
2008
|
this.pdfPassword = {ownerPassword: ownerPassword};
|
|
1083
2009
|
else this.pdfPassword.ownerPassword = ownerPassword;
|
|
1084
2010
|
this.pdfDocumentId = await setOwnerPasswords(
|
|
1085
|
-
await this.
|
|
2011
|
+
await this.internal_getId(),
|
|
1086
2012
|
ownerPassword
|
|
1087
2013
|
);
|
|
1088
2014
|
}
|
|
@@ -1091,16 +2017,16 @@ export class PdfDocument {
|
|
|
1091
2017
|
* Sets the permissions of this PdfDocument
|
|
1092
2018
|
* @param permissions see {@link PdfPermission}
|
|
1093
2019
|
*/
|
|
1094
|
-
|
|
1095
|
-
this.pdfDocumentId = await setSecurity(await this.
|
|
2020
|
+
private async internal_setPermission(permissions: PdfPermission): Promise<void> {
|
|
2021
|
+
this.pdfDocumentId = await setSecurity(await this.internal_getId(), permissions);
|
|
1096
2022
|
}
|
|
1097
2023
|
|
|
1098
2024
|
/**
|
|
1099
2025
|
* Gets the current permissions of this PdfDocument
|
|
1100
2026
|
* @return {@link PdfPermission}
|
|
1101
2027
|
*/
|
|
1102
|
-
|
|
1103
|
-
return await getPermission(await this.
|
|
2028
|
+
private async internal_getPermission(): Promise<PdfPermission> {
|
|
2029
|
+
return await getPermission(await this.internal_getId());
|
|
1104
2030
|
}
|
|
1105
2031
|
|
|
1106
2032
|
/**
|
|
@@ -1109,9 +2035,9 @@ export class PdfDocument {
|
|
|
1109
2035
|
* @param ownerPassword The owner password for the PDF. A string for owner password is required to enable PDF encryption and
|
|
1110
2036
|
* all document security options.
|
|
1111
2037
|
*/
|
|
1112
|
-
|
|
1113
|
-
await this.
|
|
1114
|
-
await this.
|
|
2038
|
+
private async internal_makePdfDocumentReadOnly(ownerPassword: string): Promise<void> {
|
|
2039
|
+
await this.internal_setOwnerPassword(ownerPassword);
|
|
2040
|
+
await this.internal_setPermission({
|
|
1115
2041
|
AllowExtractContent: false,
|
|
1116
2042
|
AllowAccessibilityExtractContent: false,
|
|
1117
2043
|
AllowAnnotations: false,
|
|
@@ -1122,4 +2048,6 @@ export class PdfDocument {
|
|
|
1122
2048
|
}
|
|
1123
2049
|
|
|
1124
2050
|
//#endregion
|
|
2051
|
+
|
|
2052
|
+
//#endregion
|
|
1125
2053
|
}
|