@shad0wz7/nestjs-pdf 2.4.2 → 2.5.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 +14 -0
- package/dist/index.cjs +3840 -0
- package/dist/index.d.cts +530 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +481 -344
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3719 -5137
- package/dist/index.mjs.map +1 -0
- package/package.json +27 -16
- package/dist/index.d.ts +0 -393
- package/dist/index.js +0 -5196
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
import { DynamicModule, InjectionToken, ModuleMetadata, OnModuleDestroy, OnModuleInit, OptionalFactoryDependency } from "@nestjs/common";
|
|
2
|
+
import { HandlebarsOptions } from "@gboutte/nestjs-hbs/dist/handlebars-options.interface";
|
|
3
|
+
import { Browser } from "@puppeteer/browsers";
|
|
4
|
+
import { Browser as Browser$1, BrowserContext, PDFOptions } from "puppeteer";
|
|
5
|
+
import { LocalsObject, Options } from "pug";
|
|
6
|
+
import { Data, Options as Options$1 } from "ejs";
|
|
7
|
+
import { ConfigureOptions } from "nunjucks";
|
|
8
|
+
import { EtaConfig } from "eta";
|
|
9
|
+
import { EscapeFunction } from "mustache";
|
|
10
|
+
import { HandlebarsService } from "@gboutte/nestjs-hbs";
|
|
11
|
+
//#region src/puppeteer/browser/browser.service.d.ts
|
|
12
|
+
declare enum BrowserTag {
|
|
13
|
+
LATEST = "latest",
|
|
14
|
+
BETA = "beta",
|
|
15
|
+
DEV = "dev",
|
|
16
|
+
STABLE = "stable",
|
|
17
|
+
CANARY = "canary"
|
|
18
|
+
}
|
|
19
|
+
type Headless = boolean | 'shell' | undefined;
|
|
20
|
+
declare class BrowserService implements OnModuleDestroy {
|
|
21
|
+
private readonly cacheDir;
|
|
22
|
+
private readonly options?;
|
|
23
|
+
private _browserInstance;
|
|
24
|
+
private browser;
|
|
25
|
+
activeJobs: number;
|
|
26
|
+
totalJobs: number;
|
|
27
|
+
private recycleRequested;
|
|
28
|
+
private recycling;
|
|
29
|
+
private browserTag;
|
|
30
|
+
private useLockedBrowser;
|
|
31
|
+
private buildId;
|
|
32
|
+
constructor(pdfParams: PuppeteerParameters);
|
|
33
|
+
onModuleDestroy(): Promise<void>;
|
|
34
|
+
getBrowserInstance(args: string[], headless: boolean | 'shell' | undefined, executablePathBin: string | undefined): Promise<Browser$1>;
|
|
35
|
+
createContext(args: string[], headless: Headless, executablePath?: string): Promise<BrowserContext>;
|
|
36
|
+
markJobStarted(): void;
|
|
37
|
+
markJobFinished(): Promise<void>;
|
|
38
|
+
recycleBrowserIfNeeded(): Promise<void>;
|
|
39
|
+
private cleanupCacheBestEffort;
|
|
40
|
+
install(lock?: boolean): Promise<import("@puppeteer/browsers", { with: { "resolution-mode": "import" } }).InstalledBrowser | null | undefined>;
|
|
41
|
+
private registerCleanupHooks;
|
|
42
|
+
private loadBrowser;
|
|
43
|
+
setBrowser(browser: Browser): void;
|
|
44
|
+
getBrowser(): Browser;
|
|
45
|
+
private loadBrowserTag;
|
|
46
|
+
private loadBuildId;
|
|
47
|
+
setBrowserTag(browserTag: BrowserTag): void;
|
|
48
|
+
getBrowserTag(): BrowserTag;
|
|
49
|
+
getBuildId(): string | undefined;
|
|
50
|
+
setBuildId(value: string | undefined): void;
|
|
51
|
+
private loadUseLockedBrowser;
|
|
52
|
+
hasBrowserInstalled(browser: Browser, buildId: string): Promise<boolean>;
|
|
53
|
+
getExecutablePath(): Promise<string>;
|
|
54
|
+
private launchBrowser;
|
|
55
|
+
private writeLockFile;
|
|
56
|
+
getLockedBuildId(browser: Browser): string | null;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region node_modules/.pnpm/@types+mjml-core@5.1.0/node_modules/@types/mjml-core/index.d.ts
|
|
60
|
+
/**
|
|
61
|
+
* Options passed as an object to the mjml2html function
|
|
62
|
+
*
|
|
63
|
+
* https://documentation.mjml.io/#inside-node-js
|
|
64
|
+
*/
|
|
65
|
+
interface MJMLParsingOptions {
|
|
66
|
+
/**
|
|
67
|
+
* Default fonts imported in the HTML rendered by HTML
|
|
68
|
+
* ie. { 'Open Sans': 'https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,700' }
|
|
69
|
+
*
|
|
70
|
+
* default: @see https://github.com/mjmlio/mjml/blob/master/packages/mjml-core/src/index.js
|
|
71
|
+
*/
|
|
72
|
+
fonts?: {
|
|
73
|
+
[key: string]: string;
|
|
74
|
+
} | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Option to keep comments in the HTML output
|
|
77
|
+
* default: true
|
|
78
|
+
*/
|
|
79
|
+
keepComments?: boolean | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Beautify the HTML output using prettier (parser: 'html', printWidth: 240).
|
|
82
|
+
* Mutually exclusive with minify — if minify is true, beautify is skipped.
|
|
83
|
+
* Note: the CLI defaults this to true; the programmatic API defaults to false.
|
|
84
|
+
* default: false
|
|
85
|
+
*/
|
|
86
|
+
beautify?: boolean | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Minify the HTML output using htmlnano (with cssnano-preset-lite for CSS).
|
|
89
|
+
* Takes priority over beautify when both are true.
|
|
90
|
+
* default: false
|
|
91
|
+
*/
|
|
92
|
+
minify?: boolean | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Options passed to htmlnano when minify is true.
|
|
95
|
+
* The minifyCss field accepts false, true, 'lite', or a cssnano options object.
|
|
96
|
+
* All htmlnano v3 options are accepted.
|
|
97
|
+
*/
|
|
98
|
+
minifyOptions?: MJMLMinifyOptions | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* How to validate your MJML
|
|
101
|
+
*
|
|
102
|
+
* skip: your document is rendered without going through validation
|
|
103
|
+
* soft: your document is going through validation and is rendered, even if it has errors
|
|
104
|
+
* strict: your document is going through validation and is not rendered if it has any error
|
|
105
|
+
*
|
|
106
|
+
* default: soft
|
|
107
|
+
*/
|
|
108
|
+
validationLevel?: "strict" | "soft" | "skip" | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Full path of the specified file to use when resolving paths from mj-include components
|
|
111
|
+
* default: '.'
|
|
112
|
+
*/
|
|
113
|
+
filePath?: string | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Directory (or directories) outside the template's own folder from which mj-include
|
|
116
|
+
* partials may be loaded. Added in mjml 5.1 as part of the include path-traversal hardening;
|
|
117
|
+
* includes resolving outside these allowed roots are denied.
|
|
118
|
+
*/
|
|
119
|
+
includePath?: string | string[] | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* The path or directory of the .mjmlconfig file
|
|
122
|
+
* default: process.cwd()
|
|
123
|
+
*/
|
|
124
|
+
mjmlConfigPath?: string | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* Use the config attribute defined in the .mjmlconfig file.
|
|
127
|
+
* The config passed into mjml2html overrides the .mjmlconfig.
|
|
128
|
+
* default: false
|
|
129
|
+
*/
|
|
130
|
+
useMjmlConfigOptions?: boolean | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* optional setting when inlining css, see mjml-cli documentation for more info
|
|
133
|
+
*/
|
|
134
|
+
juicePreserveTags?: {
|
|
135
|
+
[index: string]: {
|
|
136
|
+
start: string;
|
|
137
|
+
end: string;
|
|
138
|
+
};
|
|
139
|
+
} | undefined;
|
|
140
|
+
juiceOptions?: any;
|
|
141
|
+
/**
|
|
142
|
+
* undocumented
|
|
143
|
+
* a function returning html skeleton
|
|
144
|
+
* default: see mjml-core/src/helpers/skeleton.js
|
|
145
|
+
*/
|
|
146
|
+
skeleton?: string | (() => string) | undefined;
|
|
147
|
+
actualPath?: string | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* undocumented
|
|
150
|
+
* ignore mj-include elements
|
|
151
|
+
* default: false
|
|
152
|
+
*/
|
|
153
|
+
ignoreIncludes?: any;
|
|
154
|
+
/**
|
|
155
|
+
* see mjml-parser-xml
|
|
156
|
+
*/
|
|
157
|
+
preprocessors?: Array<((xml: string) => string)> | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* Add media queries specific to printer when converting mjml into html. When enabling this option,
|
|
160
|
+
* the html might not be compatible with all email clients anymore.
|
|
161
|
+
*/
|
|
162
|
+
printerSupport?: boolean | undefined;
|
|
163
|
+
}
|
|
164
|
+
interface MJMLMinifyOptions {
|
|
165
|
+
collapseWhitespace?: boolean | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* CSS minification options passed to cssnano-preset-lite.
|
|
168
|
+
* Accepts false (disable), true/'lite' (use lite preset), or a cssnano options object.
|
|
169
|
+
* @see https://cssnano.co/docs/presets
|
|
170
|
+
*/
|
|
171
|
+
minifyCss?: boolean | "lite" | {
|
|
172
|
+
preset?: any;
|
|
173
|
+
plugins?: any[];
|
|
174
|
+
configFile?: string;
|
|
175
|
+
} | undefined;
|
|
176
|
+
/** @deprecated use minifyCss instead */
|
|
177
|
+
minifyCSS?: boolean | undefined;
|
|
178
|
+
removeEmptyAttributes?: boolean | undefined;
|
|
179
|
+
minifyJs?: boolean | undefined;
|
|
180
|
+
removeComments?: false | "safe" | "all" | undefined;
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/puppeteer/engines/pug/pug.service.d.ts
|
|
184
|
+
type PugOptions = Options;
|
|
185
|
+
declare class PugService {
|
|
186
|
+
render(template: string, data?: LocalsObject, options?: PugOptions): string;
|
|
187
|
+
renderFile(filePath: string, data?: LocalsObject, options?: PugOptions): string;
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/puppeteer/engines/ejs/ejs.service.d.ts
|
|
191
|
+
interface EjsOptions extends Omit<Options$1, 'async'> {
|
|
192
|
+
async?: boolean;
|
|
193
|
+
}
|
|
194
|
+
declare class EjsService {
|
|
195
|
+
render(template: string, data?: Data, options?: EjsOptions): Promise<string>;
|
|
196
|
+
renderFile(filePath: string, data?: Data, options?: EjsOptions): Promise<string>;
|
|
197
|
+
}
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/puppeteer/engines/nunjucks/nunjucks.service.d.ts
|
|
200
|
+
interface NunjucksOptions extends Partial<ConfigureOptions> {
|
|
201
|
+
noCache?: boolean;
|
|
202
|
+
watch?: boolean;
|
|
203
|
+
throwOnUndefined?: boolean;
|
|
204
|
+
trimBlocks?: boolean;
|
|
205
|
+
lstripBlocks?: boolean;
|
|
206
|
+
}
|
|
207
|
+
declare class NunjucksService {
|
|
208
|
+
constructor();
|
|
209
|
+
render(template: string, data?: Record<string, unknown>, options?: NunjucksOptions): string;
|
|
210
|
+
renderFile(filePath: string, data?: Record<string, unknown>, options?: NunjucksOptions): string;
|
|
211
|
+
}
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/puppeteer/engines/eta/eta.service.d.ts
|
|
214
|
+
interface EtaOptions extends Partial<EtaConfig> {
|
|
215
|
+
cache?: boolean;
|
|
216
|
+
autoEscape?: boolean;
|
|
217
|
+
varName?: string;
|
|
218
|
+
views?: string;
|
|
219
|
+
useWith?: boolean;
|
|
220
|
+
plugins?: any[];
|
|
221
|
+
}
|
|
222
|
+
declare class EtaService {
|
|
223
|
+
private readonly eta;
|
|
224
|
+
private readonly templateCache;
|
|
225
|
+
private readonly maxCacheSize;
|
|
226
|
+
constructor();
|
|
227
|
+
/**
|
|
228
|
+
* Render an Eta template from a string
|
|
229
|
+
* @param template The template string to render
|
|
230
|
+
* @param data The data object to use for rendering
|
|
231
|
+
* @param options Optional Eta rendering options
|
|
232
|
+
* @returns The rendered HTML string
|
|
233
|
+
*/
|
|
234
|
+
render(template: string, data?: Record<string, unknown>, options?: EtaOptions): string;
|
|
235
|
+
/**
|
|
236
|
+
* Render an Eta template from a file
|
|
237
|
+
* @param filePath The path to the template file
|
|
238
|
+
* @param data The data object to use for rendering
|
|
239
|
+
* @param options Optional Eta rendering options
|
|
240
|
+
* @returns The rendered HTML string
|
|
241
|
+
*/
|
|
242
|
+
renderFile(filePath: string, data?: Record<string, unknown>, options?: EtaOptions): string;
|
|
243
|
+
/**
|
|
244
|
+
* Clear the template cache
|
|
245
|
+
*/
|
|
246
|
+
clearCache(): void;
|
|
247
|
+
/**
|
|
248
|
+
* Get the current cache size
|
|
249
|
+
* @returns The number of cached templates
|
|
250
|
+
*/
|
|
251
|
+
getCacheSize(): number;
|
|
252
|
+
}
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/puppeteer/engines/mustache/mustache.service.d.ts
|
|
255
|
+
interface MustacheOptions {
|
|
256
|
+
tags?: [string, string];
|
|
257
|
+
escape?: EscapeFunction;
|
|
258
|
+
}
|
|
259
|
+
declare class MustacheService {
|
|
260
|
+
private readonly templateCache;
|
|
261
|
+
private readonly maxCacheSize;
|
|
262
|
+
/**
|
|
263
|
+
* Render a Mustache template from a string
|
|
264
|
+
* @param template The template string to render
|
|
265
|
+
* @param data The data object to use for rendering
|
|
266
|
+
* @param options Optional Mustache rendering options
|
|
267
|
+
* @returns The rendered HTML string
|
|
268
|
+
*/
|
|
269
|
+
render(template: string, data?: Record<string, unknown>, options?: MustacheOptions): string;
|
|
270
|
+
/**
|
|
271
|
+
* Render a Mustache template from a file
|
|
272
|
+
* @param filePath The path to the template file
|
|
273
|
+
* @param data The data object to use for rendering
|
|
274
|
+
* @param options Optional Mustache rendering options
|
|
275
|
+
* @returns The rendered HTML string
|
|
276
|
+
*/
|
|
277
|
+
renderFile(filePath: string, data?: Record<string, unknown>, options?: MustacheOptions): string;
|
|
278
|
+
/**
|
|
279
|
+
* Clear the template cache
|
|
280
|
+
*/
|
|
281
|
+
clearCache(): void;
|
|
282
|
+
/**
|
|
283
|
+
* Get the current cache size
|
|
284
|
+
* @returns The number of cached templates
|
|
285
|
+
*/
|
|
286
|
+
getCacheSize(): number;
|
|
287
|
+
}
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/puppeteer/puppeteer-parameters.interface.d.ts
|
|
290
|
+
interface PuppeteerParameters {
|
|
291
|
+
pdfOptions?: PDFOptions;
|
|
292
|
+
hbsOptions?: HandlebarsOptions;
|
|
293
|
+
mjmlOptions?: MJMLParsingOptions;
|
|
294
|
+
pugOptions?: PugOptions;
|
|
295
|
+
ejsOptions?: EjsOptions;
|
|
296
|
+
nunjucksOptions?: NunjucksOptions;
|
|
297
|
+
etaOptions?: EtaOptions;
|
|
298
|
+
mustacheOptions?: MustacheOptions;
|
|
299
|
+
chromiumRevision?: string;
|
|
300
|
+
buildId?: string;
|
|
301
|
+
headless?: boolean | 'shell';
|
|
302
|
+
browser?: Browser;
|
|
303
|
+
browserTag?: BrowserTag;
|
|
304
|
+
useLockedBrowser?: boolean;
|
|
305
|
+
browserInstallBaseUrl?: string;
|
|
306
|
+
extraPuppeteerArgs?: string[];
|
|
307
|
+
executablePath?: string;
|
|
308
|
+
cleanupBrowserCacheOnExit?: boolean;
|
|
309
|
+
}
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/nestjs-pdf.module.d.ts
|
|
312
|
+
interface PdfLibModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
313
|
+
inject?: any[];
|
|
314
|
+
useFactory: (...args: any[]) => any;
|
|
315
|
+
}
|
|
316
|
+
declare class NestjsPdfModule {
|
|
317
|
+
static forRoot(options: PuppeteerParameters): DynamicModule;
|
|
318
|
+
static forRootAsync(options: PdfLibModuleAsyncOptions): DynamicModule;
|
|
319
|
+
}
|
|
320
|
+
//#endregion
|
|
321
|
+
//#region src/puppeteer/engines/mjml/mjml.service.d.ts
|
|
322
|
+
declare class MjmlService {
|
|
323
|
+
render(template: string, options?: MJMLParsingOptions): Promise<string>;
|
|
324
|
+
renderFile(filePath: string, options?: MJMLParsingOptions): Promise<string>;
|
|
325
|
+
}
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/puppeteer/puppeteer.service.d.ts
|
|
328
|
+
declare class PuppeteerService {
|
|
329
|
+
private readonly browserService;
|
|
330
|
+
private readonly options;
|
|
331
|
+
private readonly hbsService?;
|
|
332
|
+
private readonly mjmlService?;
|
|
333
|
+
private readonly pugService?;
|
|
334
|
+
private readonly ejsService?;
|
|
335
|
+
private readonly nunjucksService?;
|
|
336
|
+
private readonly etaService?;
|
|
337
|
+
private readonly mustacheService?;
|
|
338
|
+
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);
|
|
339
|
+
private readonly limit;
|
|
340
|
+
generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array>;
|
|
341
|
+
generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
342
|
+
generatePdfFromTemplateHbsFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
343
|
+
generatePdfFromMjmlString(template: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
344
|
+
generatePdfFromMjmlFile(file: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
345
|
+
generatePdfFromPugString(template: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
346
|
+
generatePdfFromPugFile(file: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
347
|
+
generatePdfFromEjsString(template: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
348
|
+
generatePdfFromEjsFile(file: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
349
|
+
generatePdfFromNunjucksString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
350
|
+
generatePdfFromNunjucksFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
351
|
+
generatePdfFromEtaString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
352
|
+
generatePdfFromEtaFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
353
|
+
generatePdfFromMustacheString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
354
|
+
generatePdfFromMustacheFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
355
|
+
}
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/nestjs-pdf.service.d.ts
|
|
358
|
+
declare class NestjsPdfService {
|
|
359
|
+
private readonly puppeteerService;
|
|
360
|
+
constructor(puppeteerService: PuppeteerService);
|
|
361
|
+
/**
|
|
362
|
+
* @param html HTML string to convert to PDF
|
|
363
|
+
* @param options PDF generation options (optional)
|
|
364
|
+
* @returns PDF generated from the provided HTML
|
|
365
|
+
* @description This method uses the Puppeteer service to generate a PDF from an HTML string. Generation options can be customized by passing a `PuppeteerParameters` object as the second argument. This allows you to control various aspects of PDF rendering, such as page size, margins, background display, etc. If no options are provided, the default parameters defined in the Puppeteer service will be used.
|
|
366
|
+
*/
|
|
367
|
+
generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
368
|
+
/**
|
|
369
|
+
* @param template Handlebars template string
|
|
370
|
+
* @param parameters Data parameters to inject into the template
|
|
371
|
+
* @param options PDF generation options (optional)
|
|
372
|
+
* @returns PDF generated from the provided Handlebars template with parameters applied
|
|
373
|
+
* @description This method generates a PDF from a Handlebars template provided as a string. The parameters to inject into the template are passed in the `parameters` object, which is used to render the template before converting it to PDF. PDF generation options can also be customized by passing a `PuppeteerParameters` object as the third argument. This allows you to control various aspects of PDF rendering, such as page size, margins, background display, etc. If no options are provided, the default parameters defined in the Puppeteer service will be used.
|
|
374
|
+
*/
|
|
375
|
+
generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
376
|
+
/**
|
|
377
|
+
* @param file Path to the Handlebars template file
|
|
378
|
+
* @param parameters Data parameters to inject into the template
|
|
379
|
+
* @param options PDF generation options (optional)
|
|
380
|
+
* @returns PDF generated from the Handlebars template at the provided file path with parameters applied
|
|
381
|
+
* @description This method generates a PDF from a Handlebars template located at the specified file path. The file path is passed as a string in the `file` parameter. The parameters to inject into the template are passed in the `parameters` object, which is used to render the template before converting it to PDF. PDF generation options can also be customized by passing a `PuppeteerParameters` object as the third argument. This allows you to control various aspects of PDF rendering, such as page size, margins, background display, etc. If no options are provided, the default parameters defined in the Puppeteer service will be used.
|
|
382
|
+
*/
|
|
383
|
+
generatePdfFromTemplateHbsFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
384
|
+
/**
|
|
385
|
+
* @param template MJML template string
|
|
386
|
+
* @param options PDF generation options (optional)
|
|
387
|
+
* @returns PDF generated from the provided MJML template
|
|
388
|
+
* @description This method generates a PDF from an MJML template provided as a string. MJML (MJML Markup Language) is a markup language designed to reduce the pain of coding a responsive email. The template is first rendered to HTML using the MJML renderer, then converted to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the second argument.
|
|
389
|
+
*/
|
|
390
|
+
generatePdfFromMjmlString(template: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
391
|
+
/**
|
|
392
|
+
* @param file Path to the MJML template file
|
|
393
|
+
* @param options PDF generation options (optional)
|
|
394
|
+
* @returns PDF generated from the MJML template at the provided file path
|
|
395
|
+
* @description This method generates a PDF from an MJML template located at the specified file path. The file path is passed as a string in the `file` parameter. The template is first rendered to HTML using the MJML renderer, then converted to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the second argument.
|
|
396
|
+
*/
|
|
397
|
+
generatePdfFromMjmlFile(file: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
398
|
+
/**
|
|
399
|
+
* @param template EJS template string
|
|
400
|
+
* @param data Data to inject into the template
|
|
401
|
+
* @param options PDF generation options (optional)
|
|
402
|
+
* @returns PDF generated from the provided EJS template with data applied
|
|
403
|
+
* @description This method generates a PDF from an EJS (Embedded JavaScript) template provided as a string. EJS is a templating language with a simple, straightforward syntax. 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.
|
|
404
|
+
*/
|
|
405
|
+
generatePdfFromEjsString(template: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
406
|
+
/**
|
|
407
|
+
* @param file Path to the EJS template file
|
|
408
|
+
* @param data Data to inject into the template
|
|
409
|
+
* @param options PDF generation options (optional)
|
|
410
|
+
* @returns PDF generated from the EJS template at the provided file path with data applied
|
|
411
|
+
* @description This method generates a PDF from an EJS 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.
|
|
412
|
+
*/
|
|
413
|
+
generatePdfFromEjsFile(file: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
414
|
+
/**
|
|
415
|
+
* @param template Pug template string
|
|
416
|
+
* @param data Data to inject into the template
|
|
417
|
+
* @param options PDF generation options (optional)
|
|
418
|
+
* @returns PDF generated from the provided Pug template with data applied
|
|
419
|
+
* @description This method generates a PDF from a Pug template provided as a string. Pug is a clean, whitespace-sensitive syntax for writing HTML. 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.
|
|
420
|
+
*/
|
|
421
|
+
generatePdfFromPugString(template: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
422
|
+
/**
|
|
423
|
+
* @param file Path to the Pug template file
|
|
424
|
+
* @param data Data to inject into the template
|
|
425
|
+
* @param options PDF generation options (optional)
|
|
426
|
+
* @returns PDF generated from the Pug template at the provided file path with data applied
|
|
427
|
+
* @description This method generates a PDF from a Pug 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.
|
|
428
|
+
*/
|
|
429
|
+
generatePdfFromPugFile(file: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
430
|
+
/**
|
|
431
|
+
* @param template Nunjucks template string
|
|
432
|
+
* @param data Data to inject into the template
|
|
433
|
+
* @param options PDF generation options (optional)
|
|
434
|
+
* @returns PDF generated from the provided Nunjucks template with data applied
|
|
435
|
+
* @description This method generates a PDF from a Nunjucks template provided as a string. Nunjucks is a powerful templating language with support for inheritance, macros, and filters. 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.
|
|
436
|
+
*/
|
|
437
|
+
generatePdfFromNunjucksString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
438
|
+
/**
|
|
439
|
+
* @param file Path to the Nunjucks template file
|
|
440
|
+
* @param data Data to inject into the template
|
|
441
|
+
* @param options PDF generation options (optional)
|
|
442
|
+
* @returns PDF generated from the Nunjucks template at the provided file path with data applied
|
|
443
|
+
* @description This method generates a PDF from a Nunjucks 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.
|
|
444
|
+
*/
|
|
445
|
+
generatePdfFromNunjucksFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
446
|
+
/**
|
|
447
|
+
* @param template Eta template string
|
|
448
|
+
* @param data Data to inject into the template
|
|
449
|
+
* @param options PDF generation options (optional)
|
|
450
|
+
* @returns PDF generated from the provided Eta template with data applied
|
|
451
|
+
* @description This method generates a PDF from an Eta template provided as a string. Eta is a fast and lightweight embedded templating language with a syntax similar to EJS but with better performance. 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.
|
|
452
|
+
*/
|
|
453
|
+
generatePdfFromEtaString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
454
|
+
/**
|
|
455
|
+
* @param file Path to the Eta template file
|
|
456
|
+
* @param data Data to inject into the template
|
|
457
|
+
* @param options PDF generation options (optional)
|
|
458
|
+
* @returns PDF generated from the Eta template at the provided file path with data applied
|
|
459
|
+
* @description This method generates a PDF from an Eta 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.
|
|
460
|
+
*/
|
|
461
|
+
generatePdfFromEtaFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
462
|
+
/**
|
|
463
|
+
* @param template Mustache template string
|
|
464
|
+
* @param data Data to inject into the template
|
|
465
|
+
* @param options PDF generation options (optional)
|
|
466
|
+
* @returns PDF generated from the provided Mustache template with data applied
|
|
467
|
+
* @description This method generates a PDF from a Mustache template provided as a string. Mustache is a logic-less template language that emphasizes readable and simple templates. 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.
|
|
468
|
+
*/
|
|
469
|
+
generatePdfFromMustacheString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
470
|
+
/**
|
|
471
|
+
* @param file Path to the Mustache template file
|
|
472
|
+
* @param data Data to inject into the template
|
|
473
|
+
* @param options PDF generation options (optional)
|
|
474
|
+
* @returns PDF generated from the Mustache template at the provided file path with data applied
|
|
475
|
+
* @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.
|
|
476
|
+
*/
|
|
477
|
+
generatePdfFromMustacheFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
478
|
+
/**
|
|
479
|
+
* @param pdf The PDF bytes to modify
|
|
480
|
+
* @param fieldName The name of the signature field to add (default: 'SignatureDebtor')
|
|
481
|
+
* @param anchorText The text anchor to locate the signature field position (default: '__SIG_DEBTOR_ANCHOR__')
|
|
482
|
+
* @returns Modified PDF with a signature field added at the anchor position
|
|
483
|
+
* @description This method adds a signature field to a PDF using a text anchor as a reference for the field position. It uses the `addSignatureFieldUsingAnchor` function which finds the anchor in the PDF and inserts a signature field at that location. The signature field is named according to the `fieldName` parameter and the anchor is defined by `anchorText`.
|
|
484
|
+
*
|
|
485
|
+
* Usage example:
|
|
486
|
+
* ```typescript
|
|
487
|
+
* const modifiedPdf = await pdfService.addSignatureFieldSignatureDebtorRaw(
|
|
488
|
+
* originalPdfBytes,
|
|
489
|
+
* 'SignatureDebtor',
|
|
490
|
+
* '__SIG_DEBTOR_ANCHOR__'
|
|
491
|
+
* );
|
|
492
|
+
* ```
|
|
493
|
+
*
|
|
494
|
+
* In this example, `originalPdfBytes` is a byte array representing the original PDF, `SignatureDebtor` is the name of the signature field to add, and `__SIG_DEBTOR_ANCHOR__` is the anchor text used to position the signature field in the PDF.
|
|
495
|
+
*
|
|
496
|
+
* If the anchor is not found, the signature field will be added at a default position (centered at the bottom of the last page).
|
|
497
|
+
*
|
|
498
|
+
* 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.
|
|
499
|
+
*/
|
|
500
|
+
addSignatureFieldSignatureDebtorRaw(pdf: Uint8Array | Buffer, fieldName?: string, anchorText?: string): Promise<Uint8Array<ArrayBufferLike>>;
|
|
501
|
+
}
|
|
502
|
+
//#endregion
|
|
503
|
+
//#region src/puppeteer/puppeteer.module.d.ts
|
|
504
|
+
interface PuppeteerModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
505
|
+
inject?: (InjectionToken | OptionalFactoryDependency)[];
|
|
506
|
+
useFactory: (...args: any[]) => Promise<PuppeteerParameters> | PuppeteerParameters;
|
|
507
|
+
}
|
|
508
|
+
declare class PuppeteerModule implements OnModuleInit {
|
|
509
|
+
private readonly browserService;
|
|
510
|
+
private readonly pdfParams;
|
|
511
|
+
constructor(browserService: BrowserService, pdfParams: PuppeteerParameters);
|
|
512
|
+
onModuleInit(): Promise<void>;
|
|
513
|
+
static forRoot(pdfParameters: PuppeteerParameters): DynamicModule;
|
|
514
|
+
static forRootAsync(options: PuppeteerModuleAsyncOptions): DynamicModule;
|
|
515
|
+
}
|
|
516
|
+
//#endregion
|
|
517
|
+
//#region src/helpers/getRelativePath.helper.d.ts
|
|
518
|
+
/**
|
|
519
|
+
* Get the relative path to a value from the module directory.
|
|
520
|
+
* @param moduleDir the path of the module, typically __dirname
|
|
521
|
+
* @param relativeToModule the path to the value relative to the module directory
|
|
522
|
+
* @returns the relative path from the current working directory to the value
|
|
523
|
+
* @example
|
|
524
|
+
* getRelativePathToValue(__dirname, './templates/my-template.hbs');
|
|
525
|
+
* // returns 'context/pdf/templates/my-template.hbs' if the current working directory is '/
|
|
526
|
+
*/
|
|
527
|
+
declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
|
|
528
|
+
//#endregion
|
|
529
|
+
export { EjsOptions, EjsService, EtaOptions, EtaService, MjmlService, MustacheOptions, MustacheService, NestjsPdfModule, NestjsPdfService, NunjucksOptions, NunjucksService, PdfLibModuleAsyncOptions, PugOptions, PugService, PuppeteerModule, PuppeteerModuleAsyncOptions, PuppeteerParameters, PuppeteerService, getRelativePathToValue };
|
|
530
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/puppeteer/browser/browser.service.ts","../node_modules/.pnpm/@types+mjml-core@5.1.0/node_modules/@types/mjml-core/index.d.ts","../src/puppeteer/engines/pug/pug.service.ts","../src/puppeteer/engines/ejs/ejs.service.ts","../src/puppeteer/engines/nunjucks/nunjucks.service.ts","../src/puppeteer/engines/eta/eta.service.ts","../src/puppeteer/engines/mustache/mustache.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","../src/helpers/getRelativePath.helper.ts"],"x_google_ignoreList":[1],"mappings":";;;;;;;;;;;aAeY;EACV;EACA;EACA;EACA;EACA;;KAGU;cAqCC,0BAA0B;mBACpB;mBACA;UAET;UACA;EAED;EACA;UAEC;UACA;UAEA;UACA;UACA;EAE8B,YAAA,WAAW;EAc3C,mBAAe;EAgBf,mBACJ,gBACA,yCACA,wCAAqC,QAAA;EAajC,cACJ,gBACA,UAAU,UACV,0BACC,QAAQ;EA2BX;EASM,mBAAe;EAKf,0BAAsB;UA6Bd;EA6BR,QAAQ,iBAAqB,wCAAA,yCAAA;UA2D3B;UAuBA;EAUD,WAAW,SAAS;EAIpB,cAAc;UAIb;UAcA;EAUD,cAAc,YAAY;EAI1B,iBAAiB;EAIxB;EAIA,WAAW;UAIH;EAUF,oBAAoB,SAAS,SAAa,kBAAe;EAczD,qBAAqB;UA8Bb;UAwBN;EAYR,iBAAiB,SAAS;;;;;;;;;UC1bX;;;;;;;EAOb;KAAW;;;;;;EAMX;;;;;;;EAQA;;;;;;EAOA;;;;;;EAOA,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