@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/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "@shad0wz7/nestjs-pdf",
3
- "version": "2.4.2",
4
- "description": "A NestJS library for generating PDFs with Puppeteer and Handlebars.",
3
+ "version": "2.5.0",
4
+ "description": "A NestJS library for generating PDFs with Puppeteer and multiple engines.",
5
+ "packageManager": "pnpm@11.18.0+sha512.33d83c77da82f49fba836925c6f1b841181ec3132b670639bd012f7075f5c7cf634c5f870147c19aae7478fac01df09d8892e880454896edd23ee9b33757563c",
5
6
  "author": "Emmanuel Boisset",
6
7
  "license": "MIT",
7
8
  "type": "commonjs",
8
- "main": "./dist/index.js",
9
+ "main": "./dist/index.cjs",
9
10
  "module": "./dist/index.mjs",
10
- "types": "./dist/index.d.ts",
11
+ "types": "./dist/index.d.cts",
11
12
  "exports": {
12
13
  ".": {
13
- "types": "./dist/index.d.ts",
14
- "require": "./dist/index.js",
15
- "import": "./dist/index.mjs"
14
+ "types": "./dist/index.d.cts",
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.cjs"
16
17
  }
17
18
  },
18
19
  "files": [
@@ -21,7 +22,8 @@
21
22
  "LICENSE"
22
23
  ],
23
24
  "scripts": {
24
- "build": "tsup",
25
+ "build:dev": "tsdown --watch ./src",
26
+ "build": "tsdown",
25
27
  "prepublishOnly": "pnpm lint && pnpm test && pnpm build",
26
28
  "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
27
29
  "lint": "eslint \"{src,test}/**/*.ts\" --fix",
@@ -56,8 +58,8 @@
56
58
  "deepmerge-ts": "^7.1.5",
57
59
  "p-limit": "^7.3.1",
58
60
  "pdf-lib": "^1.17.1",
59
- "pdfjs-dist": "^6.1.200",
60
- "puppeteer": "^25.3.0"
61
+ "pdfjs-dist": "^6.2.108",
62
+ "puppeteer": "^25.4.0"
61
63
  },
62
64
  "devDependencies": {
63
65
  "@eslint/eslintrc": "^3.3.6",
@@ -66,20 +68,20 @@
66
68
  "@nestjs/config": "^4.0.4",
67
69
  "@nestjs/schematics": "^11.1.0",
68
70
  "@nestjs/testing": "^11.1.28",
69
- "@swc/core": "^1.15.46",
71
+ "@swc/core": "^1.15.47",
70
72
  "@types/ejs": "^3.1.5",
71
73
  "@types/jest": "^30.0.0",
72
74
  "@types/mjml": "^5.0.0",
73
75
  "@types/mjml-core": "^5.1.0",
74
76
  "@types/mustache": "^4.2.6",
75
- "@types/node": "^26.1.1",
77
+ "@types/node": "^26.1.2",
76
78
  "@types/nunjucks": "^3.2.6",
77
79
  "@types/pug": "^2.0.10",
78
80
  "@types/supertest": "^7.2.1",
79
81
  "eslint": "^10.8.0",
80
82
  "eslint-config-prettier": "^10.1.8",
81
83
  "eslint-plugin-prettier": "^5.5.6",
82
- "globals": "^17.7.0",
84
+ "globals": "^17.8.0",
83
85
  "husky": "^9.1.7",
84
86
  "jest": "^30.4.2",
85
87
  "prettier": "^3.9.6",
@@ -90,13 +92,14 @@
90
92
  "ts-loader": "^9.6.2",
91
93
  "ts-node": "^10.9.2",
92
94
  "tsconfig-paths": "^4.2.0",
93
- "tsup": "^8.5.1",
95
+ "tsdown": "^0.22.14",
96
+ "tsx": "^4.23.1",
94
97
  "typescript": "^6.0.3",
95
98
  "typescript-eslint": "^8.65.0"
96
99
  },
97
100
  "optionalDependencies": {
98
101
  "@gboutte/nestjs-hbs": "^0.2.0",
99
- "@napi-rs/canvas": "^1.0.2",
102
+ "@napi-rs/canvas": "^1.0.3",
100
103
  "ejs": "^6.0.1",
101
104
  "eta": "^4.6.0",
102
105
  "mjml": "^5.4.0",
@@ -104,6 +107,13 @@
104
107
  "nunjucks": "^3.2.4",
105
108
  "pug": "^3.0.4"
106
109
  },
110
+ "inlinedDependencies": {
111
+ "@nestjs/config": "4.0.4",
112
+ "@types/mjml-core": "5.1.0",
113
+ "dotenv": "17.4.1",
114
+ "dotenv-expand": "12.0.3",
115
+ "lodash": "4.18.1"
116
+ },
107
117
  "repository": {
108
118
  "url": "git+https://github.com/ShadowZ11/nestjs-pdf.git"
109
119
  },
@@ -134,7 +144,8 @@
134
144
  "/node_modules/\\.pnpm/(?!(puppeteer[@+]|puppeteer-core[@+]|@puppeteer\\+))"
135
145
  ],
136
146
  "collectCoverageFrom": [
137
- "src/**/*.(t|j)s"
147
+ "src/**/*.(t|j)s",
148
+ "!src/index.ts"
138
149
  ],
139
150
  "coverageDirectory": "./coverage",
140
151
  "testEnvironment": "node",
package/dist/index.d.ts DELETED
@@ -1,393 +0,0 @@
1
- import { OnModuleDestroy, DynamicModule, ModuleMetadata, OnModuleInit, InjectionToken, OptionalFactoryDependency } from '@nestjs/common';
2
- import { HandlebarsOptions } from '@gboutte/nestjs-hbs/dist/handlebars-options.interface';
3
- import * as _puppeteer_browsers from '@puppeteer/browsers';
4
- import { Browser as Browser$1 } from '@puppeteer/browsers';
5
- import { Browser, BrowserContext, PDFOptions } from 'puppeteer';
6
- import { MJMLParsingOptions } from 'mjml-core';
7
- import { Options, LocalsObject } from 'pug';
8
- import { Options as Options$1, Data } from 'ejs';
9
- import { ConfigureOptions } from 'nunjucks';
10
- import { EtaConfig } from 'eta';
11
- import { EscapeFunction } from 'mustache';
12
- import { HandlebarsService } from '@gboutte/nestjs-hbs';
13
-
14
- declare enum BrowserTag {
15
- LATEST = "latest",
16
- BETA = "beta",
17
- DEV = "dev",
18
- STABLE = "stable",
19
- CANARY = "canary"
20
- }
21
- declare class BrowserService implements OnModuleDestroy {
22
- private readonly cacheDir;
23
- private readonly options?;
24
- private _browserInstance;
25
- private browser;
26
- activeJobs: number;
27
- totalJobs: number;
28
- private recycleRequested;
29
- private recycling;
30
- private browserTag;
31
- private useLockedBrowser;
32
- private buildId;
33
- constructor(pdfParams: PuppeteerParameters);
34
- onModuleDestroy(): Promise<void>;
35
- getBrowserInstance(args: string[], headless: boolean | 'shell' | undefined, executablePathBin: string | undefined): Promise<Browser>;
36
- createContext(args: string[], headless: boolean | 'shell' | undefined, executablePath?: string): Promise<BrowserContext>;
37
- markJobStarted(): void;
38
- markJobFinished(): Promise<void>;
39
- recycleBrowserIfNeeded(): Promise<void>;
40
- private cleanupCacheBestEffort;
41
- install(lock?: boolean): Promise<_puppeteer_browsers.InstalledBrowser | null | undefined>;
42
- private registerCleanupHooks;
43
- private loadBrowser;
44
- setBrowser(browser: Browser$1): void;
45
- getBrowser(): Browser$1;
46
- private loadBrowserTag;
47
- private loadBuildId;
48
- setBrowserTag(browserTag: BrowserTag): void;
49
- getBrowserTag(): BrowserTag;
50
- getBuildId(): string | undefined;
51
- setBuildId(value: string | undefined): void;
52
- private loadUseLockedBrowser;
53
- hasBrowserInstalled(browser: Browser$1, buildId: string): Promise<boolean>;
54
- getExecutablePath(): Promise<string>;
55
- private writeLockFile;
56
- getLockedBuildId(browser: Browser$1): string | null;
57
- }
58
-
59
- type PugOptions = Options;
60
- declare class PugService {
61
- render(template: string, data?: LocalsObject, options?: PugOptions): string;
62
- renderFile(filePath: string, data?: LocalsObject, options?: PugOptions): string;
63
- }
64
-
65
- interface EjsOptions extends Omit<Options$1, 'async'> {
66
- async?: boolean;
67
- }
68
- declare class EjsService {
69
- render(template: string, data?: Data, options?: EjsOptions): Promise<string>;
70
- renderFile(filePath: string, data?: Data, options?: EjsOptions): Promise<string>;
71
- }
72
-
73
- interface NunjucksOptions extends Partial<ConfigureOptions> {
74
- noCache?: boolean;
75
- watch?: boolean;
76
- throwOnUndefined?: boolean;
77
- trimBlocks?: boolean;
78
- lstripBlocks?: boolean;
79
- }
80
- declare class NunjucksService {
81
- constructor();
82
- render(template: string, data?: Record<string, unknown>, options?: NunjucksOptions): string;
83
- renderFile(filePath: string, data?: Record<string, unknown>, options?: NunjucksOptions): string;
84
- }
85
-
86
- interface EtaOptions extends Partial<EtaConfig> {
87
- cache?: boolean;
88
- autoEscape?: boolean;
89
- varName?: string;
90
- views?: string;
91
- useWith?: boolean;
92
- plugins?: any[];
93
- }
94
- declare class EtaService {
95
- private eta;
96
- private readonly templateCache;
97
- private readonly maxCacheSize;
98
- constructor();
99
- /**
100
- * Render an Eta template from a string
101
- * @param template The template string to render
102
- * @param data The data object to use for rendering
103
- * @param options Optional Eta rendering options
104
- * @returns The rendered HTML string
105
- */
106
- render(template: string, data?: Record<string, unknown>, options?: EtaOptions): string;
107
- /**
108
- * Render an Eta template from a file
109
- * @param filePath The path to the template file
110
- * @param data The data object to use for rendering
111
- * @param options Optional Eta rendering options
112
- * @returns The rendered HTML string
113
- */
114
- renderFile(filePath: string, data?: Record<string, unknown>, options?: EtaOptions): string;
115
- /**
116
- * Clear the template cache
117
- */
118
- clearCache(): void;
119
- /**
120
- * Get the current cache size
121
- * @returns The number of cached templates
122
- */
123
- getCacheSize(): number;
124
- }
125
-
126
- interface MustacheOptions {
127
- tags?: [string, string];
128
- escape?: EscapeFunction;
129
- }
130
- declare class MustacheService {
131
- private readonly templateCache;
132
- private readonly maxCacheSize;
133
- /**
134
- * Render a Mustache template from a string
135
- * @param template The template string to render
136
- * @param data The data object to use for rendering
137
- * @param options Optional Mustache rendering options
138
- * @returns The rendered HTML string
139
- */
140
- render(template: string, data?: Record<string, unknown>, options?: MustacheOptions): string;
141
- /**
142
- * Render a Mustache template from a file
143
- * @param filePath The path to the template file
144
- * @param data The data object to use for rendering
145
- * @param options Optional Mustache rendering options
146
- * @returns The rendered HTML string
147
- */
148
- renderFile(filePath: string, data?: Record<string, unknown>, options?: MustacheOptions): string;
149
- /**
150
- * Clear the template cache
151
- */
152
- clearCache(): void;
153
- /**
154
- * Get the current cache size
155
- * @returns The number of cached templates
156
- */
157
- getCacheSize(): number;
158
- }
159
-
160
- interface PuppeteerParameters {
161
- pdfOptions?: PDFOptions;
162
- hbsOptions?: HandlebarsOptions;
163
- mjmlOptions?: MJMLParsingOptions;
164
- pugOptions?: PugOptions;
165
- ejsOptions?: EjsOptions;
166
- nunjucksOptions?: NunjucksOptions;
167
- etaOptions?: EtaOptions;
168
- mustacheOptions?: MustacheOptions;
169
- chromiumRevision?: string;
170
- buildId?: string;
171
- headless?: boolean | 'shell';
172
- browser?: Browser$1;
173
- browserTag?: BrowserTag;
174
- useLockedBrowser?: boolean;
175
- browserInstallBaseUrl?: string;
176
- extraPuppeteerArgs?: string[];
177
- executablePath?: string;
178
- cleanupBrowserCacheOnExit?: boolean;
179
- }
180
-
181
- interface PdfLibModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
182
- inject?: any[];
183
- useFactory: (...args: any[]) => any;
184
- }
185
- declare class NestjsPdfModule {
186
- static forRoot(options: PuppeteerParameters): DynamicModule;
187
- static forRootAsync(options: PdfLibModuleAsyncOptions): DynamicModule;
188
- }
189
-
190
- declare class MjmlService {
191
- render(template: string, options?: MJMLParsingOptions): Promise<string>;
192
- renderFile(filePath: string, options?: MJMLParsingOptions): Promise<string>;
193
- }
194
-
195
- declare class PuppeteerService {
196
- private readonly hbsService;
197
- private readonly browserService;
198
- private readonly options;
199
- private readonly mjmlService?;
200
- private readonly pugService?;
201
- private readonly ejsService?;
202
- private readonly nunjucksService?;
203
- private readonly etaService?;
204
- private readonly mustacheService?;
205
- constructor(hbsService: HandlebarsService, browserService: BrowserService, options: PuppeteerParameters, mjmlService?: MjmlService | undefined, pugService?: PugService | undefined, ejsService?: EjsService | undefined, nunjucksService?: NunjucksService | undefined, etaService?: EtaService | undefined, mustacheService?: MustacheService | undefined);
206
- private readonly limit;
207
- generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array>;
208
- generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
209
- generatePdfFromTemplateHbsFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
210
- generatePdfFromMjmlString(template: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
211
- generatePdfFromMjmlFile(file: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
212
- generatePdfFromPugString(template: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
213
- generatePdfFromPugFile(file: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
214
- generatePdfFromEjsString(template: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
215
- generatePdfFromEjsFile(file: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
216
- generatePdfFromNunjucksString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
217
- generatePdfFromNunjucksFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
218
- generatePdfFromEtaString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
219
- generatePdfFromEtaFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
220
- generatePdfFromMustacheString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
221
- generatePdfFromMustacheFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
222
- }
223
-
224
- declare class NestjsPdfService {
225
- private readonly puppeteerService;
226
- constructor(puppeteerService: PuppeteerService);
227
- /**
228
- * @param html HTML string to convert to PDF
229
- * @param options PDF generation options (optional)
230
- * @returns PDF generated from the provided HTML
231
- * @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.
232
- */
233
- generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
234
- /**
235
- * @param template Handlebars template string
236
- * @param parameters Data parameters to inject into the template
237
- * @param options PDF generation options (optional)
238
- * @returns PDF generated from the provided Handlebars template with parameters applied
239
- * @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.
240
- */
241
- generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
242
- /**
243
- * @param file Path to the Handlebars template file
244
- * @param parameters Data parameters to inject into the template
245
- * @param options PDF generation options (optional)
246
- * @returns PDF generated from the Handlebars template at the provided file path with parameters applied
247
- * @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.
248
- */
249
- generatePdfFromTemplateHbsFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
250
- /**
251
- * @param template MJML template string
252
- * @param options PDF generation options (optional)
253
- * @returns PDF generated from the provided MJML template
254
- * @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.
255
- */
256
- generatePdfFromMjmlString(template: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
257
- /**
258
- * @param file Path to the MJML template file
259
- * @param options PDF generation options (optional)
260
- * @returns PDF generated from the MJML template at the provided file path
261
- * @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.
262
- */
263
- generatePdfFromMjmlFile(file: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
264
- /**
265
- * @param template EJS template string
266
- * @param data Data to inject into the template
267
- * @param options PDF generation options (optional)
268
- * @returns PDF generated from the provided EJS template with data applied
269
- * @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.
270
- */
271
- generatePdfFromEjsString(template: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
272
- /**
273
- * @param file Path to the EJS template file
274
- * @param data Data to inject into the template
275
- * @param options PDF generation options (optional)
276
- * @returns PDF generated from the EJS template at the provided file path with data applied
277
- * @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.
278
- */
279
- generatePdfFromEjsFile(file: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
280
- /**
281
- * @param template Pug template string
282
- * @param data Data to inject into the template
283
- * @param options PDF generation options (optional)
284
- * @returns PDF generated from the provided Pug template with data applied
285
- * @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.
286
- */
287
- generatePdfFromPugString(template: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
288
- /**
289
- * @param file Path to the Pug template file
290
- * @param data Data to inject into the template
291
- * @param options PDF generation options (optional)
292
- * @returns PDF generated from the Pug template at the provided file path with data applied
293
- * @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.
294
- */
295
- generatePdfFromPugFile(file: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
296
- /**
297
- * @param template Nunjucks template string
298
- * @param data Data to inject into the template
299
- * @param options PDF generation options (optional)
300
- * @returns PDF generated from the provided Nunjucks template with data applied
301
- * @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.
302
- */
303
- generatePdfFromNunjucksString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
304
- /**
305
- * @param file Path to the Nunjucks template file
306
- * @param data Data to inject into the template
307
- * @param options PDF generation options (optional)
308
- * @returns PDF generated from the Nunjucks template at the provided file path with data applied
309
- * @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.
310
- */
311
- generatePdfFromNunjucksFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
312
- /**
313
- * @param template Eta template string
314
- * @param data Data to inject into the template
315
- * @param options PDF generation options (optional)
316
- * @returns PDF generated from the provided Eta template with data applied
317
- * @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.
318
- */
319
- generatePdfFromEtaString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
320
- /**
321
- * @param file Path to the Eta template file
322
- * @param data Data to inject into the template
323
- * @param options PDF generation options (optional)
324
- * @returns PDF generated from the Eta template at the provided file path with data applied
325
- * @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.
326
- */
327
- generatePdfFromEtaFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
328
- /**
329
- * @param template Mustache template string
330
- * @param data Data to inject into the template
331
- * @param options PDF generation options (optional)
332
- * @returns PDF generated from the provided Mustache template with data applied
333
- * @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.
334
- */
335
- generatePdfFromMustacheString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
336
- /**
337
- * @param file Path to the Mustache template file
338
- * @param data Data to inject into the template
339
- * @param options PDF generation options (optional)
340
- * @returns PDF generated from the Mustache template at the provided file path with data applied
341
- * @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.
342
- */
343
- generatePdfFromMustacheFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
344
- /**
345
- * @param pdf The PDF bytes to modify
346
- * @param fieldName The name of the signature field to add (default: 'SignatureDebtor')
347
- * @param anchorText The text anchor to locate the signature field position (default: '__SIG_DEBTOR_ANCHOR__')
348
- * @returns Modified PDF with a signature field added at the anchor position
349
- * @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`.
350
- *
351
- * Usage example:
352
- * ```typescript
353
- * const modifiedPdf = await pdfService.addSignatureFieldSignatureDebtorRaw(
354
- * originalPdfBytes,
355
- * 'SignatureDebtor',
356
- * '__SIG_DEBTOR_ANCHOR__'
357
- * );
358
- * ```
359
- *
360
- * 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.
361
- *
362
- * If the anchor is not found, the signature field will be added at a default position (centered at the bottom of the last page).
363
- *
364
- * 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.
365
- */
366
- addSignatureFieldSignatureDebtorRaw(pdf: Uint8Array | Buffer, fieldName?: string, anchorText?: string): Promise<Uint8Array<ArrayBufferLike>>;
367
- }
368
-
369
- interface PuppeteerModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
370
- inject?: (InjectionToken | OptionalFactoryDependency)[];
371
- useFactory: (...args: any[]) => Promise<PuppeteerParameters> | PuppeteerParameters;
372
- }
373
- declare class PuppeteerModule implements OnModuleInit {
374
- private readonly browserService;
375
- private readonly pdfParams;
376
- constructor(browserService: BrowserService, pdfParams: PuppeteerParameters);
377
- onModuleInit(): Promise<void>;
378
- static forRoot(pdfParameters: PuppeteerParameters): DynamicModule;
379
- static forRootAsync(options: PuppeteerModuleAsyncOptions): DynamicModule;
380
- }
381
-
382
- /**
383
- * Get the relative path to a value from the module directory.
384
- * @param moduleDir the path of the module, typically __dirname
385
- * @param relativeToModule the path to the value relative to the module directory
386
- * @returns the relative path from the current working directory to the value
387
- * @example
388
- * getRelativePathToValue(__dirname, './templates/my-template.hbs');
389
- * // returns 'context/pdf/templates/my-template.hbs' if the current working directory is '/
390
- */
391
- declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
392
-
393
- export { type EjsOptions, EjsService, type EtaOptions, EtaService, MjmlService, type MustacheOptions, MustacheService, NestjsPdfModule, NestjsPdfService, type NunjucksOptions, NunjucksService, type PdfLibModuleAsyncOptions, type PugOptions, PugService, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };