@shad0wz7/nestjs-pdf 3.0.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -6
- package/dist/index.cjs +665 -1494
- package/dist/index.d.cts +163 -54
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +163 -54
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +656 -1520
- package/dist/index.mjs.map +1 -1
- package/package.json +21 -21
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,83 @@
|
|
|
1
|
+
import { Browser, BrowserContext, PDFOptions } from "puppeteer";
|
|
2
|
+
import { StandardFonts } from "pdf-lib";
|
|
1
3
|
import { DynamicModule, InjectionToken, ModuleMetadata, OnModuleDestroy, OnModuleInit, OptionalFactoryDependency } from "@nestjs/common";
|
|
2
|
-
import { Browser } from "@puppeteer/browsers";
|
|
4
|
+
import { Browser as Browser$1 } from "@puppeteer/browsers";
|
|
3
5
|
import { MJMLParsingOptions } from "mjml-core";
|
|
4
|
-
import { Browser as Browser$1, BrowserContext, PDFOptions } from "puppeteer";
|
|
5
6
|
import { Data, Options } from "ejs";
|
|
6
7
|
import { EtaConfig } from "eta";
|
|
7
8
|
import Handlebars from "handlebars";
|
|
8
9
|
import { EscapeFunction } from "mustache";
|
|
9
10
|
import { ConfigureOptions } from "nunjucks";
|
|
10
11
|
import { LocalsObject, Options as Options$1 } from "pug";
|
|
12
|
+
//#region src/exceptions/nestjs-pdf.exception.d.ts
|
|
13
|
+
export declare enum NestjsPdfErrorCode {
|
|
14
|
+
ENGINE_NOT_AVAILABLE = "ENGINE_NOT_AVAILABLE",
|
|
15
|
+
TEMPLATE_CONFIGURATION_ERROR = "TEMPLATE_CONFIGURATION_ERROR",
|
|
16
|
+
TEMPLATE_RENDER_ERROR = "TEMPLATE_RENDER_ERROR",
|
|
17
|
+
BROWSER_INSTALLATION_ERROR = "BROWSER_INSTALLATION_ERROR",
|
|
18
|
+
BROWSER_UNAVAILABLE = "BROWSER_UNAVAILABLE",
|
|
19
|
+
PDF_GENERATION_ERROR = "PDF_GENERATION_ERROR",
|
|
20
|
+
SIGNATURE_DEPENDENCY_ERROR = "SIGNATURE_DEPENDENCY_ERROR",
|
|
21
|
+
SIGNATURE_PLACEMENT_ERROR = "SIGNATURE_PLACEMENT_ERROR",
|
|
22
|
+
WATERMARK_ERROR = "WATERMARK_ERROR"
|
|
23
|
+
}
|
|
24
|
+
export declare abstract class NestjsPdfException extends Error {
|
|
25
|
+
abstract readonly code: NestjsPdfErrorCode;
|
|
26
|
+
constructor(message: string, options?: {
|
|
27
|
+
cause?: unknown;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/exceptions/browser-installation.exception.d.ts
|
|
32
|
+
export declare class BrowserInstallationException extends NestjsPdfException {
|
|
33
|
+
readonly code = NestjsPdfErrorCode.BROWSER_INSTALLATION_ERROR;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/exceptions/browser-unavailable.exception.d.ts
|
|
37
|
+
export declare class BrowserUnavailableException extends NestjsPdfException {
|
|
38
|
+
readonly code = NestjsPdfErrorCode.BROWSER_UNAVAILABLE;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/exceptions/engine-not-available.exception.d.ts
|
|
42
|
+
export declare class EngineNotAvailableException extends NestjsPdfException {
|
|
43
|
+
readonly code = NestjsPdfErrorCode.ENGINE_NOT_AVAILABLE;
|
|
44
|
+
constructor(engineName: string);
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/exceptions/pdf-generation.exception.d.ts
|
|
48
|
+
export declare class PdfGenerationException extends NestjsPdfException {
|
|
49
|
+
readonly code = NestjsPdfErrorCode.PDF_GENERATION_ERROR;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/exceptions/signature-dependency.exception.d.ts
|
|
53
|
+
export declare class SignatureDependencyException extends NestjsPdfException {
|
|
54
|
+
readonly code = NestjsPdfErrorCode.SIGNATURE_DEPENDENCY_ERROR;
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/exceptions/signature-placement.exception.d.ts
|
|
58
|
+
export declare class SignaturePlacementException extends NestjsPdfException {
|
|
59
|
+
readonly code = NestjsPdfErrorCode.SIGNATURE_PLACEMENT_ERROR;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/exceptions/template-configuration.exception.d.ts
|
|
63
|
+
export declare class TemplateConfigurationException extends NestjsPdfException {
|
|
64
|
+
readonly code = NestjsPdfErrorCode.TEMPLATE_CONFIGURATION_ERROR;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/exceptions/template-render.exception.d.ts
|
|
68
|
+
export declare class TemplateRenderException extends NestjsPdfException {
|
|
69
|
+
readonly engine: string;
|
|
70
|
+
readonly code = NestjsPdfErrorCode.TEMPLATE_RENDER_ERROR;
|
|
71
|
+
constructor(engine: string, message: string, options?: {
|
|
72
|
+
cause?: unknown;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/exceptions/watermark.exception.d.ts
|
|
77
|
+
export declare class WatermarkException extends NestjsPdfException {
|
|
78
|
+
readonly code = NestjsPdfErrorCode.WATERMARK_ERROR;
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
11
81
|
//#region src/helpers/getRelativePath.helper.d.ts
|
|
12
82
|
/**
|
|
13
83
|
* Get the relative path to a value from the module directory.
|
|
@@ -20,6 +90,57 @@ import { LocalsObject, Options as Options$1 } from "pug";
|
|
|
20
90
|
*/
|
|
21
91
|
export declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
|
|
22
92
|
//#endregion
|
|
93
|
+
//#region src/helpers/request-guard.helper.d.ts
|
|
94
|
+
/**
|
|
95
|
+
* Filters what the rendered HTML may load (SSRF protection). Disabled unless set:
|
|
96
|
+
* pass `{}` for the defaults (private networks and `file:` blocked).
|
|
97
|
+
*/
|
|
98
|
+
interface PdfSecurityOptions {
|
|
99
|
+
/**
|
|
100
|
+
* Refuse http(s) requests that resolve to a loopback, private, link-local
|
|
101
|
+
* (cloud metadata included) or otherwise non-public address. Default: true
|
|
102
|
+
*/
|
|
103
|
+
blockPrivateNetworks?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* When set, http(s) requests are only allowed to these hosts (`example.com`
|
|
106
|
+
* or `*.example.com`). Listed hosts are trusted, even on a private address.
|
|
107
|
+
*/
|
|
108
|
+
allowedHosts?: Array<string>;
|
|
109
|
+
/**
|
|
110
|
+
* `file:` requests are refused unless the file is inside one of these
|
|
111
|
+
* directories (symbolic links are resolved).
|
|
112
|
+
*/
|
|
113
|
+
allowedFileRoots?: Array<string>;
|
|
114
|
+
/** Set to false to disable JavaScript in the rendered page. Default: true */
|
|
115
|
+
javascriptEnabled?: boolean;
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/helpers/watermark.helper.d.ts
|
|
119
|
+
interface WatermarkOptions {
|
|
120
|
+
/** Text to stamp. At least one of `text` or `image` is required. */
|
|
121
|
+
text?: string;
|
|
122
|
+
/** PNG or JPEG bytes to stamp. At least one of `text` or `image` is required. */
|
|
123
|
+
image?: Uint8Array | Buffer;
|
|
124
|
+
/** Opacity between 0 (invisible) and 1 (opaque). Default: 0.15 */
|
|
125
|
+
opacity?: number;
|
|
126
|
+
/** Counter-clockwise rotation in degrees. Default: 45 */
|
|
127
|
+
rotation?: number;
|
|
128
|
+
/** Text font size in points. Default: 60 */
|
|
129
|
+
fontSize?: number;
|
|
130
|
+
/** One of the PDF standard fonts (WinAnsi characters only). Default: 'HelveticaBold' */
|
|
131
|
+
font?: keyof typeof StandardFonts;
|
|
132
|
+
/** Text color as `#rgb` or `#rrggbb`. Default: '#808080' */
|
|
133
|
+
color?: string;
|
|
134
|
+
/** Rendered image width in points (aspect ratio preserved). Default: 50% of the page width */
|
|
135
|
+
imageWidth?: number;
|
|
136
|
+
/** `center` stamps once per page, `tile` repeats the mark across the page. Default: 'center' */
|
|
137
|
+
position?: 'center' | 'tile';
|
|
138
|
+
/** Gap in points between two marks when `position` is `tile`. Default: 100 */
|
|
139
|
+
tileSpacing?: number;
|
|
140
|
+
/** 1-based page numbers to watermark. Default: all pages */
|
|
141
|
+
pages?: Array<number>;
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
23
144
|
//#region src/puppeteer/browser/browser.service.d.ts
|
|
24
145
|
declare enum BrowserTag {
|
|
25
146
|
LATEST = "latest",
|
|
@@ -30,44 +151,26 @@ declare enum BrowserTag {
|
|
|
30
151
|
}
|
|
31
152
|
type Headless = boolean | 'shell' | undefined;
|
|
32
153
|
declare class BrowserService implements OnModuleDestroy {
|
|
33
|
-
private
|
|
34
|
-
private readonly options?;
|
|
35
|
-
private _browserInstance;
|
|
36
|
-
private browser;
|
|
154
|
+
#private;
|
|
37
155
|
activeJobs: number;
|
|
38
156
|
totalJobs: number;
|
|
39
|
-
private recycleRequested;
|
|
40
|
-
private recycling;
|
|
41
|
-
private shuttingDown;
|
|
42
157
|
/** Max time to wait for in-flight PDF jobs to finish before closing the browser on shutdown. */
|
|
43
158
|
shutdownDrainTimeoutMs: number;
|
|
44
|
-
private browserTag;
|
|
45
|
-
private useLockedBrowser;
|
|
46
|
-
private buildId;
|
|
47
159
|
constructor(pdfParams: PuppeteerParameters);
|
|
48
160
|
onModuleDestroy(): Promise<void>;
|
|
49
|
-
|
|
50
|
-
private waitForIdle;
|
|
51
|
-
getBrowserInstance(args: Array<string>, headless: boolean | 'shell' | undefined, executablePathBin: string | undefined): Promise<Browser$1>;
|
|
161
|
+
getBrowserInstance(args: Array<string>, headless: boolean | 'shell' | undefined, executablePathBin: string | undefined): Promise<Browser>;
|
|
52
162
|
createContext(args: Array<string>, headless: Headless, executablePath?: string): Promise<BrowserContext>;
|
|
53
163
|
markJobStarted(): void;
|
|
54
164
|
markJobFinished(): Promise<void>;
|
|
55
165
|
recycleBrowserIfNeeded(): Promise<void>;
|
|
56
|
-
private cleanupCacheBestEffort;
|
|
57
166
|
install(lock?: boolean): Promise<import("@puppeteer/browsers").InstalledBrowser | null | undefined>;
|
|
58
|
-
|
|
59
|
-
getBrowser(): Browser;
|
|
60
|
-
private loadBrowserTag;
|
|
61
|
-
private loadBuildId;
|
|
167
|
+
getBrowser(): Browser$1;
|
|
62
168
|
setBrowserTag(browserTag: BrowserTag): void;
|
|
63
169
|
getBrowserTag(): BrowserTag;
|
|
64
170
|
getBuildId(): string | undefined;
|
|
65
|
-
|
|
66
|
-
hasBrowserInstalled(browser: Browser, buildId: string): Promise<boolean>;
|
|
171
|
+
hasBrowserInstalled(browser: Browser$1, buildId: string): Promise<boolean>;
|
|
67
172
|
getExecutablePath(): Promise<string>;
|
|
68
|
-
|
|
69
|
-
private writeLockFile;
|
|
70
|
-
getLockedBuildId(browser: Browser): string | null;
|
|
173
|
+
getLockedBuildId(browser: Browser$1): string | null;
|
|
71
174
|
}
|
|
72
175
|
//#endregion
|
|
73
176
|
//#region src/puppeteer/engines/ejs/ejs.service.d.ts
|
|
@@ -89,9 +192,7 @@ export interface EtaOptions extends Partial<EtaConfig> {
|
|
|
89
192
|
plugins?: Array<any>;
|
|
90
193
|
}
|
|
91
194
|
export declare class EtaService {
|
|
92
|
-
private
|
|
93
|
-
private readonly templateCache;
|
|
94
|
-
private readonly maxCacheSize;
|
|
195
|
+
#private;
|
|
95
196
|
constructor();
|
|
96
197
|
/**
|
|
97
198
|
* Render an Eta template from a string
|
|
@@ -142,17 +243,9 @@ export interface HandlebarsOptions {
|
|
|
142
243
|
helpers?: Array<HandlebarsHelper>;
|
|
143
244
|
}
|
|
144
245
|
export declare class HandlebarsService {
|
|
145
|
-
private
|
|
146
|
-
private cachedEnv?;
|
|
246
|
+
#private;
|
|
147
247
|
render(template: string, parameters?: unknown, options?: HandlebarsOptions): string;
|
|
148
248
|
renderFile(file: string, parameters?: unknown, options?: HandlebarsOptions): string;
|
|
149
|
-
/**
|
|
150
|
-
* Build an isolated Handlebars environment with the given helpers/partials so
|
|
151
|
-
* nothing leaks into the global Handlebars. Memoised for the common case where
|
|
152
|
-
* the same options object is reused across calls (e.g. the module `hbsOptions`).
|
|
153
|
-
*/
|
|
154
|
-
private getEnv;
|
|
155
|
-
private registerPartials;
|
|
156
249
|
}
|
|
157
250
|
//#endregion
|
|
158
251
|
//#region src/puppeteer/engines/mustache/mustache.service.d.ts
|
|
@@ -161,8 +254,7 @@ export interface MustacheOptions {
|
|
|
161
254
|
escape?: EscapeFunction;
|
|
162
255
|
}
|
|
163
256
|
export declare class MustacheService {
|
|
164
|
-
private
|
|
165
|
-
private readonly maxCacheSize;
|
|
257
|
+
#private;
|
|
166
258
|
/**
|
|
167
259
|
* Render a Mustache template from a string
|
|
168
260
|
* @param template The template string to render
|
|
@@ -214,6 +306,14 @@ export declare class PugService {
|
|
|
214
306
|
//#region src/puppeteer/puppeteer-parameters.interface.d.ts
|
|
215
307
|
export interface PuppeteerParameters {
|
|
216
308
|
pdfOptions?: PDFOptions;
|
|
309
|
+
/**
|
|
310
|
+
* Cancels the generation when aborted, including while it waits for a free slot.
|
|
311
|
+
* The promise rejects with `signal.reason`; use `AbortSignal.timeout(ms)` for a timeout.
|
|
312
|
+
*/
|
|
313
|
+
signal?: AbortSignal;
|
|
314
|
+
/** Watermark stamped on the generated PDF. */
|
|
315
|
+
watermark?: WatermarkOptions;
|
|
316
|
+
security?: PdfSecurityOptions;
|
|
217
317
|
hbsOptions?: HandlebarsOptions;
|
|
218
318
|
mjmlOptions?: MJMLParsingOptions;
|
|
219
319
|
pugOptions?: PugOptions;
|
|
@@ -224,7 +324,7 @@ export interface PuppeteerParameters {
|
|
|
224
324
|
chromiumRevision?: string;
|
|
225
325
|
buildId?: string;
|
|
226
326
|
headless?: boolean | 'shell';
|
|
227
|
-
browser?: Browser;
|
|
327
|
+
browser?: Browser$1;
|
|
228
328
|
browserTag?: BrowserTag;
|
|
229
329
|
useLockedBrowser?: boolean;
|
|
230
330
|
browserInstallBaseUrl?: string;
|
|
@@ -251,17 +351,8 @@ export declare class MjmlService {
|
|
|
251
351
|
//#endregion
|
|
252
352
|
//#region src/puppeteer/puppeteer.service.d.ts
|
|
253
353
|
export declare class PuppeteerService {
|
|
254
|
-
private
|
|
255
|
-
|
|
256
|
-
private readonly hbsService?;
|
|
257
|
-
private readonly mjmlService?;
|
|
258
|
-
private readonly pugService?;
|
|
259
|
-
private readonly ejsService?;
|
|
260
|
-
private readonly nunjucksService?;
|
|
261
|
-
private readonly etaService?;
|
|
262
|
-
private readonly mustacheService?;
|
|
263
|
-
constructor(browserService: BrowserService, options: PuppeteerParameters, hbsService?: HandlebarsService | undefined, mjmlService?: MjmlService | undefined, pugService?: PugService | undefined, ejsService?: EjsService | undefined, nunjucksService?: NunjucksService | undefined, etaService?: EtaService | undefined, mustacheService?: MustacheService | undefined);
|
|
264
|
-
private readonly limit;
|
|
354
|
+
#private;
|
|
355
|
+
constructor(browserService: BrowserService, options: PuppeteerParameters, hbsService?: HandlebarsService, mjmlService?: MjmlService, pugService?: PugService, ejsService?: EjsService, nunjucksService?: NunjucksService, etaService?: EtaService, mustacheService?: MustacheService);
|
|
265
356
|
generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array>;
|
|
266
357
|
generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
267
358
|
generatePdfFromTemplateHbsFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
@@ -281,7 +372,7 @@ export declare class PuppeteerService {
|
|
|
281
372
|
//#endregion
|
|
282
373
|
//#region src/nestjs-pdf.service.d.ts
|
|
283
374
|
export declare class NestjsPdfService {
|
|
284
|
-
private
|
|
375
|
+
#private;
|
|
285
376
|
constructor(puppeteerService: PuppeteerService);
|
|
286
377
|
/**
|
|
287
378
|
* @param html HTML string to convert to PDF
|
|
@@ -423,6 +514,24 @@ export declare class NestjsPdfService {
|
|
|
423
514
|
* Note: Ensure that the input PDF contains the anchor defined by `anchorText` for the signature field to be positioned correctly. Otherwise, it will be added at a default position.
|
|
424
515
|
*/
|
|
425
516
|
addSignatureFieldSignatureDebtorRaw(pdf: Uint8Array | Buffer, fieldName?: string, anchorText?: string): Promise<Uint8Array<ArrayBufferLike>>;
|
|
517
|
+
/**
|
|
518
|
+
* @param pdf The PDF bytes to modify
|
|
519
|
+
* @param options Watermark options (`text` or `image` is required)
|
|
520
|
+
* @returns Modified PDF with the watermark stamped on the selected pages
|
|
521
|
+
* @description Stamps a text or image watermark on an existing PDF. By default the mark is centered, rotated by 45° at 15% opacity on every page. Use `position: 'tile'` to repeat it across the page and `pages` to target specific pages (1-based). To watermark a PDF while generating it, pass the same options as `watermark` in the `PuppeteerParameters`.
|
|
522
|
+
*
|
|
523
|
+
* ```typescript
|
|
524
|
+
* const watermarked = await pdfService.addWatermark(pdf, {
|
|
525
|
+
* text: 'CONFIDENTIAL',
|
|
526
|
+
* color: '#ff0000',
|
|
527
|
+
* opacity: 0.2,
|
|
528
|
+
* });
|
|
529
|
+
* ```
|
|
530
|
+
*
|
|
531
|
+
* Text uses the PDF standard fonts, which only support WinAnsi characters; use an `image` for anything else.
|
|
532
|
+
* @throws WatermarkException when the options are invalid or the PDF cannot be processed
|
|
533
|
+
*/
|
|
534
|
+
addWatermark(pdf: Uint8Array | Buffer, options: WatermarkOptions): Promise<Uint8Array<ArrayBufferLike>>;
|
|
426
535
|
}
|
|
427
536
|
//#endregion
|
|
428
537
|
//#region src/puppeteer/puppeteer.module.d.ts
|
|
@@ -431,12 +540,12 @@ export interface PuppeteerModuleAsyncOptions extends Pick<ModuleMetadata, 'impor
|
|
|
431
540
|
useFactory: (...args: Array<any>) => Promise<PuppeteerParameters> | PuppeteerParameters;
|
|
432
541
|
}
|
|
433
542
|
export declare class PuppeteerModule implements OnModuleInit {
|
|
434
|
-
private
|
|
435
|
-
private readonly pdfParams;
|
|
543
|
+
#private;
|
|
436
544
|
constructor(browserService: BrowserService, pdfParams: PuppeteerParameters);
|
|
437
545
|
onModuleInit(): Promise<void>;
|
|
438
546
|
static forRoot(pdfParameters: PuppeteerParameters): DynamicModule;
|
|
439
547
|
static forRootAsync(options: PuppeteerModuleAsyncOptions): DynamicModule;
|
|
440
548
|
}
|
|
441
549
|
//#endregion
|
|
550
|
+
export type { PdfSecurityOptions, WatermarkOptions };
|
|
442
551
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/helpers/getRelativePath.helper.ts","../src/puppeteer/browser/browser.service.ts","../src/puppeteer/engines/ejs/ejs.service.ts","../src/puppeteer/engines/eta/eta.service.ts","../src/puppeteer/engines/handlebars/handlebars.service.ts","../src/puppeteer/engines/mustache/mustache.service.ts","../src/puppeteer/engines/nunjucks/nunjucks.service.ts","../src/puppeteer/engines/pug/pug.service.ts","../src/puppeteer/puppeteer-parameters.interface.ts","../src/nestjs-pdf.module.ts","../src/puppeteer/engines/mjml/mjml.service.ts","../src/puppeteer/puppeteer.service.ts","../src/nestjs-pdf.service.ts","../src/puppeteer/puppeteer.module.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/exceptions/nestjs-pdf.exception.ts","../src/exceptions/browser-installation.exception.ts","../src/exceptions/browser-unavailable.exception.ts","../src/exceptions/engine-not-available.exception.ts","../src/exceptions/pdf-generation.exception.ts","../src/exceptions/signature-dependency.exception.ts","../src/exceptions/signature-placement.exception.ts","../src/exceptions/template-configuration.exception.ts","../src/exceptions/template-render.exception.ts","../src/exceptions/watermark.exception.ts","../src/helpers/getRelativePath.helper.ts","../src/helpers/request-guard.helper.ts","../src/helpers/watermark.helper.ts","../src/puppeteer/browser/browser.service.ts","../src/puppeteer/engines/ejs/ejs.service.ts","../src/puppeteer/engines/eta/eta.service.ts","../src/puppeteer/engines/handlebars/handlebars.service.ts","../src/puppeteer/engines/mustache/mustache.service.ts","../src/puppeteer/engines/nunjucks/nunjucks.service.ts","../src/puppeteer/engines/pug/pug.service.ts","../src/puppeteer/puppeteer-parameters.interface.ts","../src/nestjs-pdf.module.ts","../src/puppeteer/engines/mjml/mjml.service.ts","../src/puppeteer/puppeteer.service.ts","../src/nestjs-pdf.service.ts","../src/puppeteer/puppeteer.module.ts"],"mappings":";;;;;;;;;;;;oBAAY;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;8BAGoB,2BAA2B;oBAC7B,MAAM;EAEZ,YAAA,iBAAiB;IAAY;;;;;qBCb9B,qCAAqC;WACvC,OAAI,mBAAA;;;;qBCDF,oCAAoC;WACtC,OAAI,mBAAA;;;;qBCDF,oCAAoC;WACtC,OAAI,mBAAA;EAED,YAAA;;;;qBCHD,+BAA+B;WACjC,OAAI,mBAAA;;;;qBCDF,qCAAqC;WACvC,OAAI,mBAAA;;;;qBCDF,oCAAoC;WACtC,OAAI,mBAAA;;;;qBCDF,uCAAuC;WACzC,OAAI,mBAAA;;;;qBCDF,gCAAgC;WAIzB;WAHT,OAAI,mBAAA;EAGK,YAAA,gBAChB,iBACA;IAAY;;;;;qBCNH,2BAA2B;WAC7B,OAAI,mBAAA;;;;;;;;;;;;;wBCQC,uBACd,mBACA;;;;;;;UCYe;;;;;EAKf;;;;;EAKA,eAAe;;;;;EAKf,mBAAmB;;EAEnB;;;;UC/Be;;EAEf;;EAEA,QAAQ,aAAa;;EAErB;;EAEA;;EAEA;;EAEA,oBAAoB;;EAEpB;;EAEA;;EAEA;;EAEA;;EAEA,QAAQ;;;;aCXE;EACV;EACA;EACA;EACA;EACA;;KAGU;cAqCC,0BAA0B;;EAO9B;EACA;;EAOA;EAM+B,YAAA,WAAW;EAU3C,mBAAe;EAmCf,mBACJ,MAAM,eACN,yCACA,wCAAqC,QAAA;EA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ACK,MAAM,eACN,QAAQ,uBAAuB;;qBAwBzB,2BAA2B;;EAKpC,YAAA,gBAAgB,gBACQ,WAAW;EAM/B,gBAAY;SAQX,QAAQ,eAAe,sBAAsB;SA8B7C,aAAa,SAAS,8BAA8B"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DynamicModule, InjectionToken, ModuleMetadata, OnModuleDestroy, OnModuleInit, OptionalFactoryDependency } from "@nestjs/common";
|
|
2
|
-
import {
|
|
3
|
-
import { Browser
|
|
2
|
+
import { StandardFonts } from "pdf-lib";
|
|
3
|
+
import { Browser, BrowserContext, PDFOptions } from "puppeteer";
|
|
4
|
+
import { Browser as Browser$1 } from "@puppeteer/browsers";
|
|
4
5
|
import { Data, Options } from "ejs";
|
|
5
6
|
import { EtaConfig } from "eta";
|
|
6
7
|
import Handlebars from "handlebars";
|
|
@@ -8,6 +9,75 @@ import { EscapeFunction } from "mustache";
|
|
|
8
9
|
import { ConfigureOptions } from "nunjucks";
|
|
9
10
|
import { LocalsObject, Options as Options$1 } from "pug";
|
|
10
11
|
import { MJMLParsingOptions } from "mjml-core";
|
|
12
|
+
//#region src/exceptions/nestjs-pdf.exception.d.ts
|
|
13
|
+
export declare enum NestjsPdfErrorCode {
|
|
14
|
+
ENGINE_NOT_AVAILABLE = "ENGINE_NOT_AVAILABLE",
|
|
15
|
+
TEMPLATE_CONFIGURATION_ERROR = "TEMPLATE_CONFIGURATION_ERROR",
|
|
16
|
+
TEMPLATE_RENDER_ERROR = "TEMPLATE_RENDER_ERROR",
|
|
17
|
+
BROWSER_INSTALLATION_ERROR = "BROWSER_INSTALLATION_ERROR",
|
|
18
|
+
BROWSER_UNAVAILABLE = "BROWSER_UNAVAILABLE",
|
|
19
|
+
PDF_GENERATION_ERROR = "PDF_GENERATION_ERROR",
|
|
20
|
+
SIGNATURE_DEPENDENCY_ERROR = "SIGNATURE_DEPENDENCY_ERROR",
|
|
21
|
+
SIGNATURE_PLACEMENT_ERROR = "SIGNATURE_PLACEMENT_ERROR",
|
|
22
|
+
WATERMARK_ERROR = "WATERMARK_ERROR"
|
|
23
|
+
}
|
|
24
|
+
export declare abstract class NestjsPdfException extends Error {
|
|
25
|
+
abstract readonly code: NestjsPdfErrorCode;
|
|
26
|
+
constructor(message: string, options?: {
|
|
27
|
+
cause?: unknown;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/exceptions/browser-installation.exception.d.ts
|
|
32
|
+
export declare class BrowserInstallationException extends NestjsPdfException {
|
|
33
|
+
readonly code = NestjsPdfErrorCode.BROWSER_INSTALLATION_ERROR;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/exceptions/browser-unavailable.exception.d.ts
|
|
37
|
+
export declare class BrowserUnavailableException extends NestjsPdfException {
|
|
38
|
+
readonly code = NestjsPdfErrorCode.BROWSER_UNAVAILABLE;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/exceptions/engine-not-available.exception.d.ts
|
|
42
|
+
export declare class EngineNotAvailableException extends NestjsPdfException {
|
|
43
|
+
readonly code = NestjsPdfErrorCode.ENGINE_NOT_AVAILABLE;
|
|
44
|
+
constructor(engineName: string);
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/exceptions/pdf-generation.exception.d.ts
|
|
48
|
+
export declare class PdfGenerationException extends NestjsPdfException {
|
|
49
|
+
readonly code = NestjsPdfErrorCode.PDF_GENERATION_ERROR;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/exceptions/signature-dependency.exception.d.ts
|
|
53
|
+
export declare class SignatureDependencyException extends NestjsPdfException {
|
|
54
|
+
readonly code = NestjsPdfErrorCode.SIGNATURE_DEPENDENCY_ERROR;
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/exceptions/signature-placement.exception.d.ts
|
|
58
|
+
export declare class SignaturePlacementException extends NestjsPdfException {
|
|
59
|
+
readonly code = NestjsPdfErrorCode.SIGNATURE_PLACEMENT_ERROR;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/exceptions/template-configuration.exception.d.ts
|
|
63
|
+
export declare class TemplateConfigurationException extends NestjsPdfException {
|
|
64
|
+
readonly code = NestjsPdfErrorCode.TEMPLATE_CONFIGURATION_ERROR;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/exceptions/template-render.exception.d.ts
|
|
68
|
+
export declare class TemplateRenderException extends NestjsPdfException {
|
|
69
|
+
readonly engine: string;
|
|
70
|
+
readonly code = NestjsPdfErrorCode.TEMPLATE_RENDER_ERROR;
|
|
71
|
+
constructor(engine: string, message: string, options?: {
|
|
72
|
+
cause?: unknown;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/exceptions/watermark.exception.d.ts
|
|
77
|
+
export declare class WatermarkException extends NestjsPdfException {
|
|
78
|
+
readonly code = NestjsPdfErrorCode.WATERMARK_ERROR;
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
11
81
|
//#region src/helpers/getRelativePath.helper.d.ts
|
|
12
82
|
/**
|
|
13
83
|
* Get the relative path to a value from the module directory.
|
|
@@ -20,6 +90,57 @@ import { MJMLParsingOptions } from "mjml-core";
|
|
|
20
90
|
*/
|
|
21
91
|
export declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
|
|
22
92
|
//#endregion
|
|
93
|
+
//#region src/helpers/request-guard.helper.d.ts
|
|
94
|
+
/**
|
|
95
|
+
* Filters what the rendered HTML may load (SSRF protection). Disabled unless set:
|
|
96
|
+
* pass `{}` for the defaults (private networks and `file:` blocked).
|
|
97
|
+
*/
|
|
98
|
+
interface PdfSecurityOptions {
|
|
99
|
+
/**
|
|
100
|
+
* Refuse http(s) requests that resolve to a loopback, private, link-local
|
|
101
|
+
* (cloud metadata included) or otherwise non-public address. Default: true
|
|
102
|
+
*/
|
|
103
|
+
blockPrivateNetworks?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* When set, http(s) requests are only allowed to these hosts (`example.com`
|
|
106
|
+
* or `*.example.com`). Listed hosts are trusted, even on a private address.
|
|
107
|
+
*/
|
|
108
|
+
allowedHosts?: Array<string>;
|
|
109
|
+
/**
|
|
110
|
+
* `file:` requests are refused unless the file is inside one of these
|
|
111
|
+
* directories (symbolic links are resolved).
|
|
112
|
+
*/
|
|
113
|
+
allowedFileRoots?: Array<string>;
|
|
114
|
+
/** Set to false to disable JavaScript in the rendered page. Default: true */
|
|
115
|
+
javascriptEnabled?: boolean;
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/helpers/watermark.helper.d.ts
|
|
119
|
+
interface WatermarkOptions {
|
|
120
|
+
/** Text to stamp. At least one of `text` or `image` is required. */
|
|
121
|
+
text?: string;
|
|
122
|
+
/** PNG or JPEG bytes to stamp. At least one of `text` or `image` is required. */
|
|
123
|
+
image?: Uint8Array | Buffer;
|
|
124
|
+
/** Opacity between 0 (invisible) and 1 (opaque). Default: 0.15 */
|
|
125
|
+
opacity?: number;
|
|
126
|
+
/** Counter-clockwise rotation in degrees. Default: 45 */
|
|
127
|
+
rotation?: number;
|
|
128
|
+
/** Text font size in points. Default: 60 */
|
|
129
|
+
fontSize?: number;
|
|
130
|
+
/** One of the PDF standard fonts (WinAnsi characters only). Default: 'HelveticaBold' */
|
|
131
|
+
font?: keyof typeof StandardFonts;
|
|
132
|
+
/** Text color as `#rgb` or `#rrggbb`. Default: '#808080' */
|
|
133
|
+
color?: string;
|
|
134
|
+
/** Rendered image width in points (aspect ratio preserved). Default: 50% of the page width */
|
|
135
|
+
imageWidth?: number;
|
|
136
|
+
/** `center` stamps once per page, `tile` repeats the mark across the page. Default: 'center' */
|
|
137
|
+
position?: 'center' | 'tile';
|
|
138
|
+
/** Gap in points between two marks when `position` is `tile`. Default: 100 */
|
|
139
|
+
tileSpacing?: number;
|
|
140
|
+
/** 1-based page numbers to watermark. Default: all pages */
|
|
141
|
+
pages?: Array<number>;
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
23
144
|
//#region src/puppeteer/browser/browser.service.d.ts
|
|
24
145
|
declare enum BrowserTag {
|
|
25
146
|
LATEST = "latest",
|
|
@@ -30,44 +151,26 @@ declare enum BrowserTag {
|
|
|
30
151
|
}
|
|
31
152
|
type Headless = boolean | 'shell' | undefined;
|
|
32
153
|
declare class BrowserService implements OnModuleDestroy {
|
|
33
|
-
private
|
|
34
|
-
private readonly options?;
|
|
35
|
-
private _browserInstance;
|
|
36
|
-
private browser;
|
|
154
|
+
#private;
|
|
37
155
|
activeJobs: number;
|
|
38
156
|
totalJobs: number;
|
|
39
|
-
private recycleRequested;
|
|
40
|
-
private recycling;
|
|
41
|
-
private shuttingDown;
|
|
42
157
|
/** Max time to wait for in-flight PDF jobs to finish before closing the browser on shutdown. */
|
|
43
158
|
shutdownDrainTimeoutMs: number;
|
|
44
|
-
private browserTag;
|
|
45
|
-
private useLockedBrowser;
|
|
46
|
-
private buildId;
|
|
47
159
|
constructor(pdfParams: PuppeteerParameters);
|
|
48
160
|
onModuleDestroy(): Promise<void>;
|
|
49
|
-
|
|
50
|
-
private waitForIdle;
|
|
51
|
-
getBrowserInstance(args: Array<string>, headless: boolean | 'shell' | undefined, executablePathBin: string | undefined): Promise<Browser$1>;
|
|
161
|
+
getBrowserInstance(args: Array<string>, headless: boolean | 'shell' | undefined, executablePathBin: string | undefined): Promise<Browser>;
|
|
52
162
|
createContext(args: Array<string>, headless: Headless, executablePath?: string): Promise<BrowserContext>;
|
|
53
163
|
markJobStarted(): void;
|
|
54
164
|
markJobFinished(): Promise<void>;
|
|
55
165
|
recycleBrowserIfNeeded(): Promise<void>;
|
|
56
|
-
private cleanupCacheBestEffort;
|
|
57
166
|
install(lock?: boolean): Promise<import("@puppeteer/browsers").InstalledBrowser | null | undefined>;
|
|
58
|
-
|
|
59
|
-
getBrowser(): Browser;
|
|
60
|
-
private loadBrowserTag;
|
|
61
|
-
private loadBuildId;
|
|
167
|
+
getBrowser(): Browser$1;
|
|
62
168
|
setBrowserTag(browserTag: BrowserTag): void;
|
|
63
169
|
getBrowserTag(): BrowserTag;
|
|
64
170
|
getBuildId(): string | undefined;
|
|
65
|
-
|
|
66
|
-
hasBrowserInstalled(browser: Browser, buildId: string): Promise<boolean>;
|
|
171
|
+
hasBrowserInstalled(browser: Browser$1, buildId: string): Promise<boolean>;
|
|
67
172
|
getExecutablePath(): Promise<string>;
|
|
68
|
-
|
|
69
|
-
private writeLockFile;
|
|
70
|
-
getLockedBuildId(browser: Browser): string | null;
|
|
173
|
+
getLockedBuildId(browser: Browser$1): string | null;
|
|
71
174
|
}
|
|
72
175
|
//#endregion
|
|
73
176
|
//#region src/puppeteer/engines/ejs/ejs.service.d.ts
|
|
@@ -89,9 +192,7 @@ export interface EtaOptions extends Partial<EtaConfig> {
|
|
|
89
192
|
plugins?: Array<any>;
|
|
90
193
|
}
|
|
91
194
|
export declare class EtaService {
|
|
92
|
-
private
|
|
93
|
-
private readonly templateCache;
|
|
94
|
-
private readonly maxCacheSize;
|
|
195
|
+
#private;
|
|
95
196
|
constructor();
|
|
96
197
|
/**
|
|
97
198
|
* Render an Eta template from a string
|
|
@@ -142,17 +243,9 @@ export interface HandlebarsOptions {
|
|
|
142
243
|
helpers?: Array<HandlebarsHelper>;
|
|
143
244
|
}
|
|
144
245
|
export declare class HandlebarsService {
|
|
145
|
-
private
|
|
146
|
-
private cachedEnv?;
|
|
246
|
+
#private;
|
|
147
247
|
render(template: string, parameters?: unknown, options?: HandlebarsOptions): string;
|
|
148
248
|
renderFile(file: string, parameters?: unknown, options?: HandlebarsOptions): string;
|
|
149
|
-
/**
|
|
150
|
-
* Build an isolated Handlebars environment with the given helpers/partials so
|
|
151
|
-
* nothing leaks into the global Handlebars. Memoised for the common case where
|
|
152
|
-
* the same options object is reused across calls (e.g. the module `hbsOptions`).
|
|
153
|
-
*/
|
|
154
|
-
private getEnv;
|
|
155
|
-
private registerPartials;
|
|
156
249
|
}
|
|
157
250
|
//#endregion
|
|
158
251
|
//#region src/puppeteer/engines/mustache/mustache.service.d.ts
|
|
@@ -161,8 +254,7 @@ export interface MustacheOptions {
|
|
|
161
254
|
escape?: EscapeFunction;
|
|
162
255
|
}
|
|
163
256
|
export declare class MustacheService {
|
|
164
|
-
private
|
|
165
|
-
private readonly maxCacheSize;
|
|
257
|
+
#private;
|
|
166
258
|
/**
|
|
167
259
|
* Render a Mustache template from a string
|
|
168
260
|
* @param template The template string to render
|
|
@@ -214,6 +306,14 @@ export declare class PugService {
|
|
|
214
306
|
//#region src/puppeteer/puppeteer-parameters.interface.d.ts
|
|
215
307
|
export interface PuppeteerParameters {
|
|
216
308
|
pdfOptions?: PDFOptions;
|
|
309
|
+
/**
|
|
310
|
+
* Cancels the generation when aborted, including while it waits for a free slot.
|
|
311
|
+
* The promise rejects with `signal.reason`; use `AbortSignal.timeout(ms)` for a timeout.
|
|
312
|
+
*/
|
|
313
|
+
signal?: AbortSignal;
|
|
314
|
+
/** Watermark stamped on the generated PDF. */
|
|
315
|
+
watermark?: WatermarkOptions;
|
|
316
|
+
security?: PdfSecurityOptions;
|
|
217
317
|
hbsOptions?: HandlebarsOptions;
|
|
218
318
|
mjmlOptions?: MJMLParsingOptions;
|
|
219
319
|
pugOptions?: PugOptions;
|
|
@@ -224,7 +324,7 @@ export interface PuppeteerParameters {
|
|
|
224
324
|
chromiumRevision?: string;
|
|
225
325
|
buildId?: string;
|
|
226
326
|
headless?: boolean | 'shell';
|
|
227
|
-
browser?: Browser;
|
|
327
|
+
browser?: Browser$1;
|
|
228
328
|
browserTag?: BrowserTag;
|
|
229
329
|
useLockedBrowser?: boolean;
|
|
230
330
|
browserInstallBaseUrl?: string;
|
|
@@ -251,17 +351,8 @@ export declare class MjmlService {
|
|
|
251
351
|
//#endregion
|
|
252
352
|
//#region src/puppeteer/puppeteer.service.d.ts
|
|
253
353
|
export declare class PuppeteerService {
|
|
254
|
-
private
|
|
255
|
-
|
|
256
|
-
private readonly hbsService?;
|
|
257
|
-
private readonly mjmlService?;
|
|
258
|
-
private readonly pugService?;
|
|
259
|
-
private readonly ejsService?;
|
|
260
|
-
private readonly nunjucksService?;
|
|
261
|
-
private readonly etaService?;
|
|
262
|
-
private readonly mustacheService?;
|
|
263
|
-
constructor(browserService: BrowserService, options: PuppeteerParameters, hbsService?: HandlebarsService | undefined, mjmlService?: MjmlService | undefined, pugService?: PugService | undefined, ejsService?: EjsService | undefined, nunjucksService?: NunjucksService | undefined, etaService?: EtaService | undefined, mustacheService?: MustacheService | undefined);
|
|
264
|
-
private readonly limit;
|
|
354
|
+
#private;
|
|
355
|
+
constructor(browserService: BrowserService, options: PuppeteerParameters, hbsService?: HandlebarsService, mjmlService?: MjmlService, pugService?: PugService, ejsService?: EjsService, nunjucksService?: NunjucksService, etaService?: EtaService, mustacheService?: MustacheService);
|
|
265
356
|
generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array>;
|
|
266
357
|
generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
267
358
|
generatePdfFromTemplateHbsFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
@@ -281,7 +372,7 @@ export declare class PuppeteerService {
|
|
|
281
372
|
//#endregion
|
|
282
373
|
//#region src/nestjs-pdf.service.d.ts
|
|
283
374
|
export declare class NestjsPdfService {
|
|
284
|
-
private
|
|
375
|
+
#private;
|
|
285
376
|
constructor(puppeteerService: PuppeteerService);
|
|
286
377
|
/**
|
|
287
378
|
* @param html HTML string to convert to PDF
|
|
@@ -423,6 +514,24 @@ export declare class NestjsPdfService {
|
|
|
423
514
|
* Note: Ensure that the input PDF contains the anchor defined by `anchorText` for the signature field to be positioned correctly. Otherwise, it will be added at a default position.
|
|
424
515
|
*/
|
|
425
516
|
addSignatureFieldSignatureDebtorRaw(pdf: Uint8Array | Buffer, fieldName?: string, anchorText?: string): Promise<Uint8Array<ArrayBufferLike>>;
|
|
517
|
+
/**
|
|
518
|
+
* @param pdf The PDF bytes to modify
|
|
519
|
+
* @param options Watermark options (`text` or `image` is required)
|
|
520
|
+
* @returns Modified PDF with the watermark stamped on the selected pages
|
|
521
|
+
* @description Stamps a text or image watermark on an existing PDF. By default the mark is centered, rotated by 45° at 15% opacity on every page. Use `position: 'tile'` to repeat it across the page and `pages` to target specific pages (1-based). To watermark a PDF while generating it, pass the same options as `watermark` in the `PuppeteerParameters`.
|
|
522
|
+
*
|
|
523
|
+
* ```typescript
|
|
524
|
+
* const watermarked = await pdfService.addWatermark(pdf, {
|
|
525
|
+
* text: 'CONFIDENTIAL',
|
|
526
|
+
* color: '#ff0000',
|
|
527
|
+
* opacity: 0.2,
|
|
528
|
+
* });
|
|
529
|
+
* ```
|
|
530
|
+
*
|
|
531
|
+
* Text uses the PDF standard fonts, which only support WinAnsi characters; use an `image` for anything else.
|
|
532
|
+
* @throws WatermarkException when the options are invalid or the PDF cannot be processed
|
|
533
|
+
*/
|
|
534
|
+
addWatermark(pdf: Uint8Array | Buffer, options: WatermarkOptions): Promise<Uint8Array<ArrayBufferLike>>;
|
|
426
535
|
}
|
|
427
536
|
//#endregion
|
|
428
537
|
//#region src/puppeteer/puppeteer.module.d.ts
|
|
@@ -431,12 +540,12 @@ export interface PuppeteerModuleAsyncOptions extends Pick<ModuleMetadata, 'impor
|
|
|
431
540
|
useFactory: (...args: Array<any>) => Promise<PuppeteerParameters> | PuppeteerParameters;
|
|
432
541
|
}
|
|
433
542
|
export declare class PuppeteerModule implements OnModuleInit {
|
|
434
|
-
private
|
|
435
|
-
private readonly pdfParams;
|
|
543
|
+
#private;
|
|
436
544
|
constructor(browserService: BrowserService, pdfParams: PuppeteerParameters);
|
|
437
545
|
onModuleInit(): Promise<void>;
|
|
438
546
|
static forRoot(pdfParameters: PuppeteerParameters): DynamicModule;
|
|
439
547
|
static forRootAsync(options: PuppeteerModuleAsyncOptions): DynamicModule;
|
|
440
548
|
}
|
|
441
549
|
//#endregion
|
|
550
|
+
export type { PdfSecurityOptions, WatermarkOptions };
|
|
442
551
|
//# sourceMappingURL=index.d.mts.map
|