@shad0wz7/nestjs-pdf 2.1.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/index.d.mts +126 -10
- package/dist/index.d.ts +126 -10
- package/dist/index.js +1413 -164
- package/dist/index.mjs +1395 -148
- package/package.json +15 -5
package/README.md
CHANGED
|
@@ -35,6 +35,8 @@ To use a template engine, you need to install the corresponding package as a dep
|
|
|
35
35
|
- For Pug: `npm install pug`
|
|
36
36
|
- For MJML: `npm install mjml`
|
|
37
37
|
- For Nunjucks: `npm install nunjucks`
|
|
38
|
+
- For Eta: `npm install eta`
|
|
39
|
+
- For Mustache: `npm install mustache`
|
|
38
40
|
|
|
39
41
|
```ts
|
|
40
42
|
import { Module } from '@nestjs/common';
|
|
@@ -116,6 +118,8 @@ The library exposes Puppeteer options via the `PuppeteerParameters` interface (s
|
|
|
116
118
|
| `pugOptions` | The pug options can be found on [Pug documentation](https://pugjs.org/api/reference.html#options) |
|
|
117
119
|
| `mjmlOptions` | The mjml options can be found on [MJML documentation](https://mjml.io/documentation/#options) |
|
|
118
120
|
| `nunjucksOptions` | The nunjucks options can be found on [Nunjucks documentation](https://mozilla.github.io/nunjucks/api.html#configure) |
|
|
121
|
+
| `etaOptions` | The eta options can be found on [Eta documentation](https://eta.js.org/docs/4.x.x/api/configuration) |
|
|
122
|
+
| `mustacheOptions` | The mustache options can be found on [Mustache documentation](https://mustache.github.io/mustache.5.html) |
|
|
119
123
|
| `browser` | The browser to use for the PDF generation. By default: `Browser.CHROMIUM`. Allowed values `Browser.CHROMIUM`, `Browser.CHROMEHEADLESSSHELL`, `Browser.CHROME`, `Browser.FIREFOX`, `Browser.CHROMEDRIVER` ([Official documentation of Browser](https://pptr.dev/browsers-api/browsers.browser)) |
|
|
120
124
|
| `browserTag` | The version of the browser to use for the PDF generation. By default: `BrowserTag.LATEST` if Browser is **CHROMIUM** else `BrowserTag.STABLE`. Allowed values `BrowserTag.STABLE`, `BrowserTag.LATEST`, `BrowserTag.BETA`, `BrowserTag.DEV`, `BrowserTag.CANARY` |
|
|
121
125
|
| `browserInstallBaseUrl` | The baseUrl used for the installation of the browser. This baseUrl is passed to the [`install`](https://pptr.dev/browsers-api/browsers.install) method of `@puppeteer/browsers` |
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { OnModuleDestroy, DynamicModule, ModuleMetadata, OnModuleInit, InjectionToken, OptionalFactoryDependency } from '@nestjs/common';
|
|
2
2
|
import { HandlebarsOptions } from '@gboutte/nestjs-hbs/dist/handlebars-options.interface';
|
|
3
|
-
import * as
|
|
3
|
+
import * as _puppeteer_browsers from '@puppeteer/browsers';
|
|
4
4
|
import { Browser as Browser$1 } from '@puppeteer/browsers';
|
|
5
5
|
import { Browser, BrowserContext, PDFOptions } from 'puppeteer';
|
|
6
6
|
import { MJMLParsingOptions } from 'mjml-core';
|
|
7
|
-
import
|
|
8
|
-
import { Options, Data } from 'ejs';
|
|
7
|
+
import { Options, LocalsObject } from 'pug';
|
|
8
|
+
import { Options as Options$1, Data } from 'ejs';
|
|
9
9
|
import { ConfigureOptions } from 'nunjucks';
|
|
10
|
+
import { EtaConfig } from 'eta';
|
|
11
|
+
import { EscapeFunction } from 'mustache';
|
|
10
12
|
import { HandlebarsService } from '@gboutte/nestjs-hbs';
|
|
11
13
|
|
|
12
14
|
declare enum BrowserTag {
|
|
@@ -36,7 +38,7 @@ declare class BrowserService implements OnModuleDestroy {
|
|
|
36
38
|
markJobFinished(): Promise<void>;
|
|
37
39
|
recycleBrowserIfNeeded(): Promise<void>;
|
|
38
40
|
private cleanupCacheBestEffort;
|
|
39
|
-
install(lock?: boolean): Promise<
|
|
41
|
+
install(lock?: boolean): Promise<_puppeteer_browsers.InstalledBrowser | null | undefined>;
|
|
40
42
|
private registerCleanupHooks;
|
|
41
43
|
private loadBrowser;
|
|
42
44
|
setBrowser(browser: Browser$1): void;
|
|
@@ -54,13 +56,13 @@ declare class BrowserService implements OnModuleDestroy {
|
|
|
54
56
|
getLockedBuildId(browser: Browser$1): string | null;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
type PugOptions =
|
|
59
|
+
type PugOptions = Options;
|
|
58
60
|
declare class PugService {
|
|
59
|
-
render(template: string, data?:
|
|
60
|
-
renderFile(filePath: string, data?:
|
|
61
|
+
render(template: string, data?: LocalsObject, options?: PugOptions): string;
|
|
62
|
+
renderFile(filePath: string, data?: LocalsObject, options?: PugOptions): string;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
interface EjsOptions extends Omit<Options, 'async'> {
|
|
65
|
+
interface EjsOptions extends Omit<Options$1, 'async'> {
|
|
64
66
|
async?: boolean;
|
|
65
67
|
}
|
|
66
68
|
declare class EjsService {
|
|
@@ -81,6 +83,80 @@ declare class NunjucksService {
|
|
|
81
83
|
renderFile(filePath: string, data?: Record<string, unknown>, options?: NunjucksOptions): string;
|
|
82
84
|
}
|
|
83
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
|
+
|
|
84
160
|
interface PuppeteerParameters {
|
|
85
161
|
pdfOptions?: PDFOptions;
|
|
86
162
|
hbsOptions?: HandlebarsOptions;
|
|
@@ -88,6 +164,8 @@ interface PuppeteerParameters {
|
|
|
88
164
|
pugOptions?: PugOptions;
|
|
89
165
|
ejsOptions?: EjsOptions;
|
|
90
166
|
nunjucksOptions?: NunjucksOptions;
|
|
167
|
+
etaOptions?: EtaOptions;
|
|
168
|
+
mustacheOptions?: MustacheOptions;
|
|
91
169
|
chromiumRevision?: string;
|
|
92
170
|
buildId?: string;
|
|
93
171
|
headless?: boolean | 'shell';
|
|
@@ -121,7 +199,9 @@ declare class PuppeteerService {
|
|
|
121
199
|
private readonly pugService?;
|
|
122
200
|
private readonly ejsService?;
|
|
123
201
|
private readonly nunjucksService?;
|
|
124
|
-
|
|
202
|
+
private readonly etaService?;
|
|
203
|
+
private readonly mustacheService?;
|
|
204
|
+
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);
|
|
125
205
|
private readonly limit;
|
|
126
206
|
generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array>;
|
|
127
207
|
generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
@@ -134,6 +214,10 @@ declare class PuppeteerService {
|
|
|
134
214
|
generatePdfFromEjsFile(file: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
135
215
|
generatePdfFromNunjucksString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
136
216
|
generatePdfFromNunjucksFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
217
|
+
generatePdfFromEtaString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
218
|
+
generatePdfFromEtaFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
219
|
+
generatePdfFromMustacheString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
220
|
+
generatePdfFromMustacheFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
137
221
|
}
|
|
138
222
|
|
|
139
223
|
declare class NestjsPdfService {
|
|
@@ -224,6 +308,38 @@ declare class NestjsPdfService {
|
|
|
224
308
|
* @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.
|
|
225
309
|
*/
|
|
226
310
|
generatePdfFromNunjucksFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
311
|
+
/**
|
|
312
|
+
* @param template Eta template string
|
|
313
|
+
* @param data Data to inject into the template
|
|
314
|
+
* @param options PDF generation options (optional)
|
|
315
|
+
* @returns PDF generated from the provided Eta template with data applied
|
|
316
|
+
* @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.
|
|
317
|
+
*/
|
|
318
|
+
generatePdfFromEtaString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
319
|
+
/**
|
|
320
|
+
* @param file Path to the Eta template file
|
|
321
|
+
* @param data Data to inject into the template
|
|
322
|
+
* @param options PDF generation options (optional)
|
|
323
|
+
* @returns PDF generated from the Eta template at the provided file path with data applied
|
|
324
|
+
* @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.
|
|
325
|
+
*/
|
|
326
|
+
generatePdfFromEtaFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
327
|
+
/**
|
|
328
|
+
* @param template Mustache template string
|
|
329
|
+
* @param data Data to inject into the template
|
|
330
|
+
* @param options PDF generation options (optional)
|
|
331
|
+
* @returns PDF generated from the provided Mustache template with data applied
|
|
332
|
+
* @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.
|
|
333
|
+
*/
|
|
334
|
+
generatePdfFromMustacheString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
335
|
+
/**
|
|
336
|
+
* @param file Path to the Mustache template file
|
|
337
|
+
* @param data Data to inject into the template
|
|
338
|
+
* @param options PDF generation options (optional)
|
|
339
|
+
* @returns PDF generated from the Mustache template at the provided file path with data applied
|
|
340
|
+
* @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.
|
|
341
|
+
*/
|
|
342
|
+
generatePdfFromMustacheFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
227
343
|
/**
|
|
228
344
|
* @param pdf The PDF bytes to modify
|
|
229
345
|
* @param fieldName The name of the signature field to add (default: 'SignatureDebtor')
|
|
@@ -273,4 +389,4 @@ declare class PuppeteerModule implements OnModuleInit {
|
|
|
273
389
|
*/
|
|
274
390
|
declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
|
|
275
391
|
|
|
276
|
-
export { type EjsOptions, EjsService, MjmlService, NestjsPdfModule, NestjsPdfService, type NunjucksOptions, NunjucksService, type PdfLibModuleAsyncOptions, type PugOptions, PugService, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };
|
|
392
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { OnModuleDestroy, DynamicModule, ModuleMetadata, OnModuleInit, InjectionToken, OptionalFactoryDependency } from '@nestjs/common';
|
|
2
2
|
import { HandlebarsOptions } from '@gboutte/nestjs-hbs/dist/handlebars-options.interface';
|
|
3
|
-
import * as
|
|
3
|
+
import * as _puppeteer_browsers from '@puppeteer/browsers';
|
|
4
4
|
import { Browser as Browser$1 } from '@puppeteer/browsers';
|
|
5
5
|
import { Browser, BrowserContext, PDFOptions } from 'puppeteer';
|
|
6
6
|
import { MJMLParsingOptions } from 'mjml-core';
|
|
7
|
-
import
|
|
8
|
-
import { Options, Data } from 'ejs';
|
|
7
|
+
import { Options, LocalsObject } from 'pug';
|
|
8
|
+
import { Options as Options$1, Data } from 'ejs';
|
|
9
9
|
import { ConfigureOptions } from 'nunjucks';
|
|
10
|
+
import { EtaConfig } from 'eta';
|
|
11
|
+
import { EscapeFunction } from 'mustache';
|
|
10
12
|
import { HandlebarsService } from '@gboutte/nestjs-hbs';
|
|
11
13
|
|
|
12
14
|
declare enum BrowserTag {
|
|
@@ -36,7 +38,7 @@ declare class BrowserService implements OnModuleDestroy {
|
|
|
36
38
|
markJobFinished(): Promise<void>;
|
|
37
39
|
recycleBrowserIfNeeded(): Promise<void>;
|
|
38
40
|
private cleanupCacheBestEffort;
|
|
39
|
-
install(lock?: boolean): Promise<
|
|
41
|
+
install(lock?: boolean): Promise<_puppeteer_browsers.InstalledBrowser | null | undefined>;
|
|
40
42
|
private registerCleanupHooks;
|
|
41
43
|
private loadBrowser;
|
|
42
44
|
setBrowser(browser: Browser$1): void;
|
|
@@ -54,13 +56,13 @@ declare class BrowserService implements OnModuleDestroy {
|
|
|
54
56
|
getLockedBuildId(browser: Browser$1): string | null;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
type PugOptions =
|
|
59
|
+
type PugOptions = Options;
|
|
58
60
|
declare class PugService {
|
|
59
|
-
render(template: string, data?:
|
|
60
|
-
renderFile(filePath: string, data?:
|
|
61
|
+
render(template: string, data?: LocalsObject, options?: PugOptions): string;
|
|
62
|
+
renderFile(filePath: string, data?: LocalsObject, options?: PugOptions): string;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
interface EjsOptions extends Omit<Options, 'async'> {
|
|
65
|
+
interface EjsOptions extends Omit<Options$1, 'async'> {
|
|
64
66
|
async?: boolean;
|
|
65
67
|
}
|
|
66
68
|
declare class EjsService {
|
|
@@ -81,6 +83,80 @@ declare class NunjucksService {
|
|
|
81
83
|
renderFile(filePath: string, data?: Record<string, unknown>, options?: NunjucksOptions): string;
|
|
82
84
|
}
|
|
83
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
|
+
|
|
84
160
|
interface PuppeteerParameters {
|
|
85
161
|
pdfOptions?: PDFOptions;
|
|
86
162
|
hbsOptions?: HandlebarsOptions;
|
|
@@ -88,6 +164,8 @@ interface PuppeteerParameters {
|
|
|
88
164
|
pugOptions?: PugOptions;
|
|
89
165
|
ejsOptions?: EjsOptions;
|
|
90
166
|
nunjucksOptions?: NunjucksOptions;
|
|
167
|
+
etaOptions?: EtaOptions;
|
|
168
|
+
mustacheOptions?: MustacheOptions;
|
|
91
169
|
chromiumRevision?: string;
|
|
92
170
|
buildId?: string;
|
|
93
171
|
headless?: boolean | 'shell';
|
|
@@ -121,7 +199,9 @@ declare class PuppeteerService {
|
|
|
121
199
|
private readonly pugService?;
|
|
122
200
|
private readonly ejsService?;
|
|
123
201
|
private readonly nunjucksService?;
|
|
124
|
-
|
|
202
|
+
private readonly etaService?;
|
|
203
|
+
private readonly mustacheService?;
|
|
204
|
+
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);
|
|
125
205
|
private readonly limit;
|
|
126
206
|
generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array>;
|
|
127
207
|
generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
@@ -134,6 +214,10 @@ declare class PuppeteerService {
|
|
|
134
214
|
generatePdfFromEjsFile(file: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
135
215
|
generatePdfFromNunjucksString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
136
216
|
generatePdfFromNunjucksFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
217
|
+
generatePdfFromEtaString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
218
|
+
generatePdfFromEtaFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
219
|
+
generatePdfFromMustacheString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
220
|
+
generatePdfFromMustacheFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
137
221
|
}
|
|
138
222
|
|
|
139
223
|
declare class NestjsPdfService {
|
|
@@ -224,6 +308,38 @@ declare class NestjsPdfService {
|
|
|
224
308
|
* @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.
|
|
225
309
|
*/
|
|
226
310
|
generatePdfFromNunjucksFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
311
|
+
/**
|
|
312
|
+
* @param template Eta template string
|
|
313
|
+
* @param data Data to inject into the template
|
|
314
|
+
* @param options PDF generation options (optional)
|
|
315
|
+
* @returns PDF generated from the provided Eta template with data applied
|
|
316
|
+
* @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.
|
|
317
|
+
*/
|
|
318
|
+
generatePdfFromEtaString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
319
|
+
/**
|
|
320
|
+
* @param file Path to the Eta template file
|
|
321
|
+
* @param data Data to inject into the template
|
|
322
|
+
* @param options PDF generation options (optional)
|
|
323
|
+
* @returns PDF generated from the Eta template at the provided file path with data applied
|
|
324
|
+
* @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.
|
|
325
|
+
*/
|
|
326
|
+
generatePdfFromEtaFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
327
|
+
/**
|
|
328
|
+
* @param template Mustache template string
|
|
329
|
+
* @param data Data to inject into the template
|
|
330
|
+
* @param options PDF generation options (optional)
|
|
331
|
+
* @returns PDF generated from the provided Mustache template with data applied
|
|
332
|
+
* @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.
|
|
333
|
+
*/
|
|
334
|
+
generatePdfFromMustacheString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
335
|
+
/**
|
|
336
|
+
* @param file Path to the Mustache template file
|
|
337
|
+
* @param data Data to inject into the template
|
|
338
|
+
* @param options PDF generation options (optional)
|
|
339
|
+
* @returns PDF generated from the Mustache template at the provided file path with data applied
|
|
340
|
+
* @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.
|
|
341
|
+
*/
|
|
342
|
+
generatePdfFromMustacheFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
227
343
|
/**
|
|
228
344
|
* @param pdf The PDF bytes to modify
|
|
229
345
|
* @param fieldName The name of the signature field to add (default: 'SignatureDebtor')
|
|
@@ -273,4 +389,4 @@ declare class PuppeteerModule implements OnModuleInit {
|
|
|
273
389
|
*/
|
|
274
390
|
declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
|
|
275
391
|
|
|
276
|
-
export { type EjsOptions, EjsService, MjmlService, NestjsPdfModule, NestjsPdfService, type NunjucksOptions, NunjucksService, type PdfLibModuleAsyncOptions, type PugOptions, PugService, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };
|
|
392
|
+
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 };
|