@shad0wz7/nestjs-pdf 3.1.0 → 4.0.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 +126 -28
- package/dist/index.cjs +594 -1380
- package/dist/index.d.cts +276 -13
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +276 -13
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +588 -1377
- package/dist/index.mjs.map +1 -1
- package/package.json +86 -47
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
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";
|
|
3
|
-
import { MJMLParsingOptions } from "mjml-core";
|
|
4
|
-
import { Browser as Browser$1, BrowserContext, PDFOptions } from "puppeteer";
|
|
4
|
+
import { Browser as Browser$1 } from "@puppeteer/browsers";
|
|
5
5
|
import { Data, Options } from "ejs";
|
|
6
6
|
import { EtaConfig } from "eta";
|
|
7
7
|
import Handlebars from "handlebars";
|
|
8
|
+
import { LiquidOptions as LiquidOptions$1 } from "liquidjs";
|
|
8
9
|
import { EscapeFunction } from "mustache";
|
|
9
10
|
import { ConfigureOptions } from "nunjucks";
|
|
10
11
|
import { LocalsObject, Options as Options$1 } from "pug";
|
|
@@ -17,7 +18,8 @@ export declare enum NestjsPdfErrorCode {
|
|
|
17
18
|
BROWSER_UNAVAILABLE = "BROWSER_UNAVAILABLE",
|
|
18
19
|
PDF_GENERATION_ERROR = "PDF_GENERATION_ERROR",
|
|
19
20
|
SIGNATURE_DEPENDENCY_ERROR = "SIGNATURE_DEPENDENCY_ERROR",
|
|
20
|
-
SIGNATURE_PLACEMENT_ERROR = "SIGNATURE_PLACEMENT_ERROR"
|
|
21
|
+
SIGNATURE_PLACEMENT_ERROR = "SIGNATURE_PLACEMENT_ERROR",
|
|
22
|
+
WATERMARK_ERROR = "WATERMARK_ERROR"
|
|
21
23
|
}
|
|
22
24
|
export declare abstract class NestjsPdfException extends Error {
|
|
23
25
|
abstract readonly code: NestjsPdfErrorCode;
|
|
@@ -39,7 +41,9 @@ export declare class BrowserUnavailableException extends NestjsPdfException {
|
|
|
39
41
|
//#region src/exceptions/engine-not-available.exception.d.ts
|
|
40
42
|
export declare class EngineNotAvailableException extends NestjsPdfException {
|
|
41
43
|
readonly code = NestjsPdfErrorCode.ENGINE_NOT_AVAILABLE;
|
|
42
|
-
constructor(engineName: string
|
|
44
|
+
constructor(engineName: string, packageName?: string, options?: {
|
|
45
|
+
cause?: unknown;
|
|
46
|
+
});
|
|
43
47
|
}
|
|
44
48
|
//#endregion
|
|
45
49
|
//#region src/exceptions/pdf-generation.exception.d.ts
|
|
@@ -71,6 +75,11 @@ export declare class TemplateRenderException extends NestjsPdfException {
|
|
|
71
75
|
});
|
|
72
76
|
}
|
|
73
77
|
//#endregion
|
|
78
|
+
//#region src/exceptions/watermark.exception.d.ts
|
|
79
|
+
export declare class WatermarkException extends NestjsPdfException {
|
|
80
|
+
readonly code = NestjsPdfErrorCode.WATERMARK_ERROR;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
74
83
|
//#region src/helpers/getRelativePath.helper.d.ts
|
|
75
84
|
/**
|
|
76
85
|
* Get the relative path to a value from the module directory.
|
|
@@ -83,6 +92,181 @@ export declare class TemplateRenderException extends NestjsPdfException {
|
|
|
83
92
|
*/
|
|
84
93
|
export declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
|
|
85
94
|
//#endregion
|
|
95
|
+
//#region src/helpers/request-guard.helper.d.ts
|
|
96
|
+
/**
|
|
97
|
+
* Filters what the rendered HTML may load (SSRF protection). Disabled unless set:
|
|
98
|
+
* pass `{}` for the defaults (private networks and `file:` blocked).
|
|
99
|
+
*/
|
|
100
|
+
interface PdfSecurityOptions {
|
|
101
|
+
/**
|
|
102
|
+
* Refuse http(s) requests that resolve to a loopback, private, link-local
|
|
103
|
+
* (cloud metadata included) or otherwise non-public address. Default: true
|
|
104
|
+
*/
|
|
105
|
+
blockPrivateNetworks?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* When set, http(s) requests are only allowed to these hosts (`example.com`
|
|
108
|
+
* or `*.example.com`). Listed hosts are trusted, even on a private address.
|
|
109
|
+
*/
|
|
110
|
+
allowedHosts?: Array<string>;
|
|
111
|
+
/**
|
|
112
|
+
* `file:` requests are refused unless the file is inside one of these
|
|
113
|
+
* directories (symbolic links are resolved).
|
|
114
|
+
*/
|
|
115
|
+
allowedFileRoots?: Array<string>;
|
|
116
|
+
/** Set to false to disable JavaScript in the rendered page. Default: true */
|
|
117
|
+
javascriptEnabled?: boolean;
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/helpers/watermark.helper.d.ts
|
|
121
|
+
interface WatermarkOptions {
|
|
122
|
+
/** Text to stamp. At least one of `text` or `image` is required. */
|
|
123
|
+
text?: string;
|
|
124
|
+
/** PNG or JPEG bytes to stamp. At least one of `text` or `image` is required. */
|
|
125
|
+
image?: Uint8Array | Buffer;
|
|
126
|
+
/** Opacity between 0 (invisible) and 1 (opaque). Default: 0.15 */
|
|
127
|
+
opacity?: number;
|
|
128
|
+
/** Counter-clockwise rotation in degrees. Default: 45 */
|
|
129
|
+
rotation?: number;
|
|
130
|
+
/** Text font size in points. Default: 60 */
|
|
131
|
+
fontSize?: number;
|
|
132
|
+
/** One of the PDF standard fonts (WinAnsi characters only). Default: 'HelveticaBold' */
|
|
133
|
+
font?: keyof typeof StandardFonts;
|
|
134
|
+
/** Text color as `#rgb` or `#rrggbb`. Default: '#808080' */
|
|
135
|
+
color?: string;
|
|
136
|
+
/** Rendered image width in points (aspect ratio preserved). Default: 50% of the page width */
|
|
137
|
+
imageWidth?: number;
|
|
138
|
+
/** `center` stamps once per page, `tile` repeats the mark across the page. Default: 'center' */
|
|
139
|
+
position?: 'center' | 'tile';
|
|
140
|
+
/** Gap in points between two marks when `position` is `tile`. Default: 100 */
|
|
141
|
+
tileSpacing?: number;
|
|
142
|
+
/** 1-based page numbers to watermark. Default: all pages */
|
|
143
|
+
pages?: Array<number>;
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region node_modules/.pnpm/@types+mjml-core@5.1.0/node_modules/@types/mjml-core/index.d.ts
|
|
147
|
+
/**
|
|
148
|
+
* Options passed as an object to the mjml2html function
|
|
149
|
+
*
|
|
150
|
+
* https://documentation.mjml.io/#inside-node-js
|
|
151
|
+
*/
|
|
152
|
+
interface MJMLParsingOptions {
|
|
153
|
+
/**
|
|
154
|
+
* Default fonts imported in the HTML rendered by HTML
|
|
155
|
+
* ie. { 'Open Sans': 'https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,700' }
|
|
156
|
+
*
|
|
157
|
+
* default: @see https://github.com/mjmlio/mjml/blob/master/packages/mjml-core/src/index.js
|
|
158
|
+
*/
|
|
159
|
+
fonts?: {
|
|
160
|
+
[key: string]: string;
|
|
161
|
+
} | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Option to keep comments in the HTML output
|
|
164
|
+
* default: true
|
|
165
|
+
*/
|
|
166
|
+
keepComments?: boolean | undefined;
|
|
167
|
+
/**
|
|
168
|
+
* Beautify the HTML output using prettier (parser: 'html', printWidth: 240).
|
|
169
|
+
* Mutually exclusive with minify — if minify is true, beautify is skipped.
|
|
170
|
+
* Note: the CLI defaults this to true; the programmatic API defaults to false.
|
|
171
|
+
* default: false
|
|
172
|
+
*/
|
|
173
|
+
beautify?: boolean | undefined;
|
|
174
|
+
/**
|
|
175
|
+
* Minify the HTML output using htmlnano (with cssnano-preset-lite for CSS).
|
|
176
|
+
* Takes priority over beautify when both are true.
|
|
177
|
+
* default: false
|
|
178
|
+
*/
|
|
179
|
+
minify?: boolean | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* Options passed to htmlnano when minify is true.
|
|
182
|
+
* The minifyCss field accepts false, true, 'lite', or a cssnano options object.
|
|
183
|
+
* All htmlnano v3 options are accepted.
|
|
184
|
+
*/
|
|
185
|
+
minifyOptions?: MJMLMinifyOptions | undefined;
|
|
186
|
+
/**
|
|
187
|
+
* How to validate your MJML
|
|
188
|
+
*
|
|
189
|
+
* skip: your document is rendered without going through validation
|
|
190
|
+
* soft: your document is going through validation and is rendered, even if it has errors
|
|
191
|
+
* strict: your document is going through validation and is not rendered if it has any error
|
|
192
|
+
*
|
|
193
|
+
* default: soft
|
|
194
|
+
*/
|
|
195
|
+
validationLevel?: "strict" | "soft" | "skip" | undefined;
|
|
196
|
+
/**
|
|
197
|
+
* Full path of the specified file to use when resolving paths from mj-include components
|
|
198
|
+
* default: '.'
|
|
199
|
+
*/
|
|
200
|
+
filePath?: string | undefined;
|
|
201
|
+
/**
|
|
202
|
+
* Directory (or directories) outside the template's own folder from which mj-include
|
|
203
|
+
* partials may be loaded. Added in mjml 5.1 as part of the include path-traversal hardening;
|
|
204
|
+
* includes resolving outside these allowed roots are denied.
|
|
205
|
+
*/
|
|
206
|
+
includePath?: string | string[] | undefined;
|
|
207
|
+
/**
|
|
208
|
+
* The path or directory of the .mjmlconfig file
|
|
209
|
+
* default: process.cwd()
|
|
210
|
+
*/
|
|
211
|
+
mjmlConfigPath?: string | undefined;
|
|
212
|
+
/**
|
|
213
|
+
* Use the config attribute defined in the .mjmlconfig file.
|
|
214
|
+
* The config passed into mjml2html overrides the .mjmlconfig.
|
|
215
|
+
* default: false
|
|
216
|
+
*/
|
|
217
|
+
useMjmlConfigOptions?: boolean | undefined;
|
|
218
|
+
/**
|
|
219
|
+
* optional setting when inlining css, see mjml-cli documentation for more info
|
|
220
|
+
*/
|
|
221
|
+
juicePreserveTags?: {
|
|
222
|
+
[index: string]: {
|
|
223
|
+
start: string;
|
|
224
|
+
end: string;
|
|
225
|
+
};
|
|
226
|
+
} | undefined;
|
|
227
|
+
juiceOptions?: any;
|
|
228
|
+
/**
|
|
229
|
+
* undocumented
|
|
230
|
+
* a function returning html skeleton
|
|
231
|
+
* default: see mjml-core/src/helpers/skeleton.js
|
|
232
|
+
*/
|
|
233
|
+
skeleton?: string | (() => string) | undefined;
|
|
234
|
+
actualPath?: string | undefined;
|
|
235
|
+
/**
|
|
236
|
+
* undocumented
|
|
237
|
+
* ignore mj-include elements
|
|
238
|
+
* default: false
|
|
239
|
+
*/
|
|
240
|
+
ignoreIncludes?: any;
|
|
241
|
+
/**
|
|
242
|
+
* see mjml-parser-xml
|
|
243
|
+
*/
|
|
244
|
+
preprocessors?: Array<((xml: string) => string)> | undefined;
|
|
245
|
+
/**
|
|
246
|
+
* Add media queries specific to printer when converting mjml into html. When enabling this option,
|
|
247
|
+
* the html might not be compatible with all email clients anymore.
|
|
248
|
+
*/
|
|
249
|
+
printerSupport?: boolean | undefined;
|
|
250
|
+
}
|
|
251
|
+
interface MJMLMinifyOptions {
|
|
252
|
+
collapseWhitespace?: boolean | undefined;
|
|
253
|
+
/**
|
|
254
|
+
* CSS minification options passed to cssnano-preset-lite.
|
|
255
|
+
* Accepts false (disable), true/'lite' (use lite preset), or a cssnano options object.
|
|
256
|
+
* @see https://cssnano.co/docs/presets
|
|
257
|
+
*/
|
|
258
|
+
minifyCss?: boolean | "lite" | {
|
|
259
|
+
preset?: any;
|
|
260
|
+
plugins?: any[];
|
|
261
|
+
configFile?: string;
|
|
262
|
+
} | undefined;
|
|
263
|
+
/** @deprecated use minifyCss instead */
|
|
264
|
+
minifyCSS?: boolean | undefined;
|
|
265
|
+
removeEmptyAttributes?: boolean | undefined;
|
|
266
|
+
minifyJs?: boolean | undefined;
|
|
267
|
+
removeComments?: false | "safe" | "all" | undefined;
|
|
268
|
+
}
|
|
269
|
+
//#endregion
|
|
86
270
|
//#region src/puppeteer/browser/browser.service.d.ts
|
|
87
271
|
declare enum BrowserTag {
|
|
88
272
|
LATEST = "latest",
|
|
@@ -100,19 +284,19 @@ declare class BrowserService implements OnModuleDestroy {
|
|
|
100
284
|
shutdownDrainTimeoutMs: number;
|
|
101
285
|
constructor(pdfParams: PuppeteerParameters);
|
|
102
286
|
onModuleDestroy(): Promise<void>;
|
|
103
|
-
getBrowserInstance(args: Array<string>, headless: boolean | 'shell' | undefined, executablePathBin: string | undefined): Promise<Browser
|
|
287
|
+
getBrowserInstance(args: Array<string>, headless: boolean | 'shell' | undefined, executablePathBin: string | undefined): Promise<Browser>;
|
|
104
288
|
createContext(args: Array<string>, headless: Headless, executablePath?: string): Promise<BrowserContext>;
|
|
105
289
|
markJobStarted(): void;
|
|
106
290
|
markJobFinished(): Promise<void>;
|
|
107
291
|
recycleBrowserIfNeeded(): Promise<void>;
|
|
108
292
|
install(lock?: boolean): Promise<import("@puppeteer/browsers").InstalledBrowser | null | undefined>;
|
|
109
|
-
getBrowser(): Browser;
|
|
293
|
+
getBrowser(): Browser$1;
|
|
110
294
|
setBrowserTag(browserTag: BrowserTag): void;
|
|
111
295
|
getBrowserTag(): BrowserTag;
|
|
112
296
|
getBuildId(): string | undefined;
|
|
113
|
-
hasBrowserInstalled(browser: Browser, buildId: string): Promise<boolean>;
|
|
297
|
+
hasBrowserInstalled(browser: Browser$1, buildId: string): Promise<boolean>;
|
|
114
298
|
getExecutablePath(): Promise<string>;
|
|
115
|
-
getLockedBuildId(browser: Browser): string | null;
|
|
299
|
+
getLockedBuildId(browser: Browser$1): string | null;
|
|
116
300
|
}
|
|
117
301
|
//#endregion
|
|
118
302
|
//#region src/puppeteer/engines/ejs/ejs.service.d.ts
|
|
@@ -120,6 +304,7 @@ export interface EjsOptions extends Omit<Options, 'async'> {
|
|
|
120
304
|
async?: boolean;
|
|
121
305
|
}
|
|
122
306
|
export declare class EjsService {
|
|
307
|
+
#private;
|
|
123
308
|
render(template: string, data?: Data, options?: EjsOptions): Promise<string>;
|
|
124
309
|
renderFile(filePath: string, data?: Data, options?: EjsOptions): Promise<string>;
|
|
125
310
|
}
|
|
@@ -135,7 +320,6 @@ export interface EtaOptions extends Partial<EtaConfig> {
|
|
|
135
320
|
}
|
|
136
321
|
export declare class EtaService {
|
|
137
322
|
#private;
|
|
138
|
-
constructor();
|
|
139
323
|
/**
|
|
140
324
|
* Render an Eta template from a string
|
|
141
325
|
* @param template The template string to render
|
|
@@ -190,6 +374,37 @@ export declare class HandlebarsService {
|
|
|
190
374
|
renderFile(file: string, parameters?: unknown, options?: HandlebarsOptions): string;
|
|
191
375
|
}
|
|
192
376
|
//#endregion
|
|
377
|
+
//#region src/puppeteer/engines/liquid/liquid.service.d.ts
|
|
378
|
+
export type LiquidOptions = LiquidOptions$1;
|
|
379
|
+
export declare class LiquidService {
|
|
380
|
+
#private;
|
|
381
|
+
/**
|
|
382
|
+
* Render a Liquid template from a string
|
|
383
|
+
* @param template The template string to render
|
|
384
|
+
* @param data The data object to use for rendering
|
|
385
|
+
* @param options Optional Liquid engine options
|
|
386
|
+
* @returns The rendered HTML string
|
|
387
|
+
*/
|
|
388
|
+
render(template: string, data?: Record<string, unknown>, options?: LiquidOptions): string;
|
|
389
|
+
/**
|
|
390
|
+
* Render a Liquid template from a file
|
|
391
|
+
* @param filePath The path to the template file
|
|
392
|
+
* @param data The data object to use for rendering
|
|
393
|
+
* @param options Optional Liquid engine options
|
|
394
|
+
* @returns The rendered HTML string
|
|
395
|
+
*/
|
|
396
|
+
renderFile(filePath: string, data?: Record<string, unknown>, options?: LiquidOptions): string;
|
|
397
|
+
/**
|
|
398
|
+
* Clear the template cache
|
|
399
|
+
*/
|
|
400
|
+
clearCache(): void;
|
|
401
|
+
/**
|
|
402
|
+
* Get the current cache size
|
|
403
|
+
* @returns The number of cached templates
|
|
404
|
+
*/
|
|
405
|
+
getCacheSize(): number;
|
|
406
|
+
}
|
|
407
|
+
//#endregion
|
|
193
408
|
//#region src/puppeteer/engines/mustache/mustache.service.d.ts
|
|
194
409
|
export interface MustacheOptions {
|
|
195
410
|
tags?: [string, string];
|
|
@@ -233,7 +448,7 @@ export interface NunjucksOptions extends Partial<ConfigureOptions> {
|
|
|
233
448
|
lstripBlocks?: boolean;
|
|
234
449
|
}
|
|
235
450
|
export declare class NunjucksService {
|
|
236
|
-
|
|
451
|
+
#private;
|
|
237
452
|
render(template: string, data?: Record<string, unknown>, options?: NunjucksOptions): string;
|
|
238
453
|
renderFile(filePath: string, data?: Record<string, unknown>, options?: NunjucksOptions): string;
|
|
239
454
|
}
|
|
@@ -241,6 +456,7 @@ export declare class NunjucksService {
|
|
|
241
456
|
//#region src/puppeteer/engines/pug/pug.service.d.ts
|
|
242
457
|
export type PugOptions = Options$1;
|
|
243
458
|
export declare class PugService {
|
|
459
|
+
#private;
|
|
244
460
|
render(template: string, data?: LocalsObject, options?: PugOptions): string;
|
|
245
461
|
renderFile(filePath: string, data?: LocalsObject, options?: PugOptions): string;
|
|
246
462
|
}
|
|
@@ -248,6 +464,14 @@ export declare class PugService {
|
|
|
248
464
|
//#region src/puppeteer/puppeteer-parameters.interface.d.ts
|
|
249
465
|
export interface PuppeteerParameters {
|
|
250
466
|
pdfOptions?: PDFOptions;
|
|
467
|
+
/**
|
|
468
|
+
* Cancels the generation when aborted, including while it waits for a free slot.
|
|
469
|
+
* The promise rejects with `signal.reason`; use `AbortSignal.timeout(ms)` for a timeout.
|
|
470
|
+
*/
|
|
471
|
+
signal?: AbortSignal;
|
|
472
|
+
/** Watermark stamped on the generated PDF. */
|
|
473
|
+
watermark?: WatermarkOptions;
|
|
474
|
+
security?: PdfSecurityOptions;
|
|
251
475
|
hbsOptions?: HandlebarsOptions;
|
|
252
476
|
mjmlOptions?: MJMLParsingOptions;
|
|
253
477
|
pugOptions?: PugOptions;
|
|
@@ -255,10 +479,11 @@ export interface PuppeteerParameters {
|
|
|
255
479
|
nunjucksOptions?: NunjucksOptions;
|
|
256
480
|
etaOptions?: EtaOptions;
|
|
257
481
|
mustacheOptions?: MustacheOptions;
|
|
482
|
+
liquidOptions?: LiquidOptions;
|
|
258
483
|
chromiumRevision?: string;
|
|
259
484
|
buildId?: string;
|
|
260
485
|
headless?: boolean | 'shell';
|
|
261
|
-
browser?: Browser;
|
|
486
|
+
browser?: Browser$1;
|
|
262
487
|
browserTag?: BrowserTag;
|
|
263
488
|
useLockedBrowser?: boolean;
|
|
264
489
|
browserInstallBaseUrl?: string;
|
|
@@ -279,6 +504,7 @@ export declare class NestjsPdfModule {
|
|
|
279
504
|
//#endregion
|
|
280
505
|
//#region src/puppeteer/engines/mjml/mjml.service.d.ts
|
|
281
506
|
export declare class MjmlService {
|
|
507
|
+
#private;
|
|
282
508
|
render(template: string, options?: MJMLParsingOptions): Promise<string>;
|
|
283
509
|
renderFile(filePath: string, options?: MJMLParsingOptions): Promise<string>;
|
|
284
510
|
}
|
|
@@ -286,7 +512,7 @@ export declare class MjmlService {
|
|
|
286
512
|
//#region src/puppeteer/puppeteer.service.d.ts
|
|
287
513
|
export declare class PuppeteerService {
|
|
288
514
|
#private;
|
|
289
|
-
constructor(browserService: BrowserService, options: PuppeteerParameters, hbsService?: HandlebarsService, mjmlService?: MjmlService, pugService?: PugService, ejsService?: EjsService, nunjucksService?: NunjucksService, etaService?: EtaService, mustacheService?: MustacheService);
|
|
515
|
+
constructor(browserService: BrowserService, options: PuppeteerParameters, hbsService?: HandlebarsService, mjmlService?: MjmlService, pugService?: PugService, ejsService?: EjsService, nunjucksService?: NunjucksService, etaService?: EtaService, mustacheService?: MustacheService, liquidService?: LiquidService);
|
|
290
516
|
generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array>;
|
|
291
517
|
generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
292
518
|
generatePdfFromTemplateHbsFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
@@ -302,6 +528,8 @@ export declare class PuppeteerService {
|
|
|
302
528
|
generatePdfFromEtaFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
303
529
|
generatePdfFromMustacheString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
304
530
|
generatePdfFromMustacheFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
531
|
+
generatePdfFromLiquidString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
532
|
+
generatePdfFromLiquidFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
305
533
|
}
|
|
306
534
|
//#endregion
|
|
307
535
|
//#region src/nestjs-pdf.service.d.ts
|
|
@@ -425,6 +653,22 @@ export declare class NestjsPdfService {
|
|
|
425
653
|
* @description This method generates a PDF from a Mustache template located at the specified file path. The file path is passed as a string in the `file` parameter. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
|
|
426
654
|
*/
|
|
427
655
|
generatePdfFromMustacheFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
656
|
+
/**
|
|
657
|
+
* @param template Liquid template string
|
|
658
|
+
* @param data Data to inject into the template
|
|
659
|
+
* @param options PDF generation options (optional)
|
|
660
|
+
* @returns PDF generated from the provided Liquid template with data applied
|
|
661
|
+
* @description This method generates a PDF from a Liquid template provided as a string. Liquid is a safe, Shopify-compatible template language with filters, tags, partials and layouts. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
|
|
662
|
+
*/
|
|
663
|
+
generatePdfFromLiquidString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
664
|
+
/**
|
|
665
|
+
* @param file Path to the Liquid template file
|
|
666
|
+
* @param data Data to inject into the template
|
|
667
|
+
* @param options PDF generation options (optional)
|
|
668
|
+
* @returns PDF generated from the Liquid template at the provided file path with data applied
|
|
669
|
+
* @description This method generates a PDF from a Liquid template located at the specified file path. The file path is passed as a string in the `file` parameter. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
|
|
670
|
+
*/
|
|
671
|
+
generatePdfFromLiquidFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
428
672
|
/**
|
|
429
673
|
* @param pdf The PDF bytes to modify
|
|
430
674
|
* @param fieldName The name of the signature field to add (default: 'SignatureDebtor')
|
|
@@ -448,6 +692,24 @@ export declare class NestjsPdfService {
|
|
|
448
692
|
* 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.
|
|
449
693
|
*/
|
|
450
694
|
addSignatureFieldSignatureDebtorRaw(pdf: Uint8Array | Buffer, fieldName?: string, anchorText?: string): Promise<Uint8Array<ArrayBufferLike>>;
|
|
695
|
+
/**
|
|
696
|
+
* @param pdf The PDF bytes to modify
|
|
697
|
+
* @param options Watermark options (`text` or `image` is required)
|
|
698
|
+
* @returns Modified PDF with the watermark stamped on the selected pages
|
|
699
|
+
* @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`.
|
|
700
|
+
*
|
|
701
|
+
* ```typescript
|
|
702
|
+
* const watermarked = await pdfService.addWatermark(pdf, {
|
|
703
|
+
* text: 'CONFIDENTIAL',
|
|
704
|
+
* color: '#ff0000',
|
|
705
|
+
* opacity: 0.2,
|
|
706
|
+
* });
|
|
707
|
+
* ```
|
|
708
|
+
*
|
|
709
|
+
* Text uses the PDF standard fonts, which only support WinAnsi characters; use an `image` for anything else.
|
|
710
|
+
* @throws WatermarkException when the options are invalid or the PDF cannot be processed
|
|
711
|
+
*/
|
|
712
|
+
addWatermark(pdf: Uint8Array | Buffer, options: WatermarkOptions): Promise<Uint8Array<ArrayBufferLike>>;
|
|
451
713
|
}
|
|
452
714
|
//#endregion
|
|
453
715
|
//#region src/puppeteer/puppeteer.module.d.ts
|
|
@@ -463,4 +725,5 @@ export declare class PuppeteerModule implements OnModuleInit {
|
|
|
463
725
|
static forRootAsync(options: PuppeteerModuleAsyncOptions): DynamicModule;
|
|
464
726
|
}
|
|
465
727
|
//#endregion
|
|
728
|
+
export type { PdfSecurityOptions, WatermarkOptions };
|
|
466
729
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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/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":["BrowserType","LiquidJsOptions","Options","Browser"],"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","../node_modules/.pnpm/@types+mjml-core@5.1.0/node_modules/@types/mjml-core/index.d.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/liquid/liquid.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"],"ignoreList":[13],"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;EAGX,YAAA,oBACA,sBACA;IAAY;;;;;qBCNH,+BAA+B;WACjC,OAAI,mBAAA;;;;qBCDF,qCAAqC;WACvC,OAAI,mBAAA;;;;qBCDF,oCAAoC;WACtC,OAAI,mBAAA;;;;qBCDF,uCAAuC;WACzC,OAAI,mBAAA;;;;qBCDF,gCAAgC;WAIzB;WAHT,OAA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