@shad0wz7/nestjs-pdf 2.0.0 → 2.1.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 +76 -7
- package/dist/index.d.mts +36 -20
- package/dist/index.d.ts +36 -20
- package/dist/index.js +205 -111
- package/dist/index.mjs +192 -99
- package/package.json +17 -12
package/README.md
CHANGED
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
A small NestJS library to generate and manipulate PDFs using Puppeteer and multiple template engines, including Handlebars, EJS, Pug, and MJML.
|
|
4
4
|
|
|
5
5
|
Main features:
|
|
6
|
+
|
|
6
7
|
- Generate PDFs from HTML, Handlebars, EJS, Pug or MJML templates
|
|
7
8
|
- Concurrency limiting for Puppeteer jobs (p-limit)
|
|
8
9
|
- Add signature fields based on a text anchor in an existing PDF
|
|
9
10
|
- Simple API (module and service) to integrate easily into a Nest application
|
|
10
11
|
|
|
11
|
-
> Note: this repository contains the library source. To use it in another project, you can either install it from npm or import the local package from the source.
|
|
12
|
-
|
|
13
12
|
## Installation
|
|
14
13
|
|
|
15
14
|
To add the library inside your project :
|
|
@@ -29,6 +28,14 @@ pnpm add ../path/to/nestjs-pdf
|
|
|
29
28
|
|
|
30
29
|
Import the module and configure it in your Nest application:
|
|
31
30
|
|
|
31
|
+
To use a template engine, you need to install the corresponding package as a dependency in your project:
|
|
32
|
+
|
|
33
|
+
- For Handlebars: `npm install @gboutte/nestjs-hbs`
|
|
34
|
+
- For EJS: `npm install ejs`
|
|
35
|
+
- For Pug: `npm install pug`
|
|
36
|
+
- For MJML: `npm install mjml`
|
|
37
|
+
- For Nunjucks: `npm install nunjucks`
|
|
38
|
+
|
|
32
39
|
```ts
|
|
33
40
|
import { Module } from '@nestjs/common';
|
|
34
41
|
import { NestjsPdfModule } from 'nestjs-pdf';
|
|
@@ -68,11 +75,17 @@ Use a Handlebars template (string or file):
|
|
|
68
75
|
|
|
69
76
|
```ts
|
|
70
77
|
const template = '<h1>{{title}}</h1><p>{{content}}</p>';
|
|
71
|
-
const pdf = await pdfService.generatePdfFromTemplateHbsString(template, {
|
|
78
|
+
const pdf = await pdfService.generatePdfFromTemplateHbsString(template, {
|
|
79
|
+
title: 'T',
|
|
80
|
+
content: '...',
|
|
81
|
+
});
|
|
72
82
|
```
|
|
73
83
|
|
|
74
84
|
```ts
|
|
75
|
-
const pdf = await pdfService.generatePdfFromTemplateHbsFile(filePath, {
|
|
85
|
+
const pdf = await pdfService.generatePdfFromTemplateHbsFile(filePath, {
|
|
86
|
+
title: 'T',
|
|
87
|
+
content: '...',
|
|
88
|
+
});
|
|
76
89
|
```
|
|
77
90
|
|
|
78
91
|
Add a signature field to an existing PDF (anchor-based):
|
|
@@ -94,9 +107,65 @@ If the anchor is not found, the signature field will be added at a default posit
|
|
|
94
107
|
|
|
95
108
|
The library exposes Puppeteer options via the `PuppeteerParameters` interface (see `src/puppeteer/puppeteer-parameters.interface.ts`). You can configure:
|
|
96
109
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
110
|
+
|
|
111
|
+
| | Description |
|
|
112
|
+
|-----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
113
|
+
| `pdfOptions` | The pdf options can be found on: https://pptr.dev/api/puppeteer.pdfoptions. Native Puppeteer options for `page.pdf` |
|
|
114
|
+
| `hbsOptions` | The handlebars can be found on [@gboutte/nestjs-hbs](https://github.com/gboutte/nestjs-hbs) as it use a peer dependency and not handlebars directly |
|
|
115
|
+
| `ejsOptions` | The ejs options can be found on [EJS documentation](https://ejs.co/#options) |
|
|
116
|
+
| `pugOptions` | The pug options can be found on [Pug documentation](https://pugjs.org/api/reference.html#options) |
|
|
117
|
+
| `mjmlOptions` | The mjml options can be found on [MJML documentation](https://mjml.io/documentation/#options) |
|
|
118
|
+
| `nunjucksOptions` | The nunjucks options can be found on [Nunjucks documentation](https://mozilla.github.io/nunjucks/api.html#configure) |
|
|
119
|
+
| `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
|
+
| `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
|
+
| `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` |
|
|
122
|
+
| `headless` | Define if you want to use chromium headless or not, or the old headless version (`shell`). By default it's `true`. Allowed values: `true`,`false`,`"shell"` |
|
|
123
|
+
| `useLockedBrowser` | Define if you want to use the locked version of the browser. By default it's `false`. Allowed values: `true`,`false` |
|
|
124
|
+
| `buildId` | You can force the build id. Should be `string` |
|
|
125
|
+
| `cleanupBrowserCacheOnExit` | Define if you want to clean up the browser cache folder on exit. By default it's `true`. Allowed values: `true`,`false` |
|
|
126
|
+
| `extraPuppeteerArgs` | It passes some extra arguments to Puppeteer's launch method. You can check the default args at bellow. Should be `string[]` |
|
|
127
|
+
|
|
128
|
+
these are the default extra arguments passed to Puppeteer:
|
|
129
|
+
```ts
|
|
130
|
+
[
|
|
131
|
+
'--autoplay-policy=user-gesture-required',
|
|
132
|
+
'--disable-background-networking',
|
|
133
|
+
'--disable-background-timer-throttling',
|
|
134
|
+
'--disable-backgrounding-occluded-windows',
|
|
135
|
+
'--disable-breakpad',
|
|
136
|
+
'--disable-client-side-phishing-detection',
|
|
137
|
+
'--disable-component-update',
|
|
138
|
+
'--disable-default-apps',
|
|
139
|
+
'--disable-dev-shm-usage',
|
|
140
|
+
'--disable-domain-reliability',
|
|
141
|
+
'--disable-extensions',
|
|
142
|
+
'--disable-features=AudioServiceOutOfProcess',
|
|
143
|
+
'--disable-hang-monitor',
|
|
144
|
+
'--disable-ipc-flooding-protection',
|
|
145
|
+
'--disable-notifications',
|
|
146
|
+
'--disable-offer-store-unmasked-wallet-cards',
|
|
147
|
+
'--disable-popup-blocking',
|
|
148
|
+
'--disable-print-preview',
|
|
149
|
+
'--disable-prompt-on-repost',
|
|
150
|
+
'--disable-renderer-backgrounding',
|
|
151
|
+
'--disable-setuid-sandbox',
|
|
152
|
+
'--disable-speech-api',
|
|
153
|
+
'--disable-sync',
|
|
154
|
+
'--hide-scrollbars',
|
|
155
|
+
'--ignore-gpu-blacklist',
|
|
156
|
+
'--metrics-recording-only',
|
|
157
|
+
'--mute-audio',
|
|
158
|
+
'--no-default-browser-check',
|
|
159
|
+
'--no-first-run',
|
|
160
|
+
'--no-pings',
|
|
161
|
+
'--password-store=basic',
|
|
162
|
+
'--use-gl=swiftshader',
|
|
163
|
+
'--use-mock-keychain',
|
|
164
|
+
'--disable-accelerated-2d-canvas',
|
|
165
|
+
'--no-zygote',
|
|
166
|
+
'--disable-gpu',
|
|
167
|
+
];
|
|
168
|
+
```
|
|
100
169
|
|
|
101
170
|
You can use `forRootAsync(...)` if you need to provide configuration asynchronously.
|
|
102
171
|
|
package/dist/index.d.mts
CHANGED
|
@@ -6,6 +6,7 @@ import { Browser, BrowserContext, PDFOptions } from 'puppeteer';
|
|
|
6
6
|
import { MJMLParsingOptions } from 'mjml-core';
|
|
7
7
|
import pug, { LocalsObject } from 'pug';
|
|
8
8
|
import { Options, Data } from 'ejs';
|
|
9
|
+
import { ConfigureOptions } from 'nunjucks';
|
|
9
10
|
import { HandlebarsService } from '@gboutte/nestjs-hbs';
|
|
10
11
|
|
|
11
12
|
declare enum BrowserTag {
|
|
@@ -67,12 +68,26 @@ declare class EjsService {
|
|
|
67
68
|
renderFile(filePath: string, data?: Data, options?: EjsOptions): Promise<string>;
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
interface NunjucksOptions extends Partial<ConfigureOptions> {
|
|
72
|
+
noCache?: boolean;
|
|
73
|
+
watch?: boolean;
|
|
74
|
+
throwOnUndefined?: boolean;
|
|
75
|
+
trimBlocks?: boolean;
|
|
76
|
+
lstripBlocks?: boolean;
|
|
77
|
+
}
|
|
78
|
+
declare class NunjucksService {
|
|
79
|
+
constructor();
|
|
80
|
+
render(template: string, data?: Record<string, unknown>, options?: NunjucksOptions): string;
|
|
81
|
+
renderFile(filePath: string, data?: Record<string, unknown>, options?: NunjucksOptions): string;
|
|
82
|
+
}
|
|
83
|
+
|
|
70
84
|
interface PuppeteerParameters {
|
|
71
85
|
pdfOptions?: PDFOptions;
|
|
72
86
|
hbsOptions?: HandlebarsOptions;
|
|
73
87
|
mjmlOptions?: MJMLParsingOptions;
|
|
74
88
|
pugOptions?: PugOptions;
|
|
75
89
|
ejsOptions?: EjsOptions;
|
|
90
|
+
nunjucksOptions?: NunjucksOptions;
|
|
76
91
|
chromiumRevision?: string;
|
|
77
92
|
buildId?: string;
|
|
78
93
|
headless?: boolean | 'shell';
|
|
@@ -105,7 +120,8 @@ declare class PuppeteerService {
|
|
|
105
120
|
private readonly mjmlService?;
|
|
106
121
|
private readonly pugService?;
|
|
107
122
|
private readonly ejsService?;
|
|
108
|
-
|
|
123
|
+
private readonly nunjucksService?;
|
|
124
|
+
constructor(hbsService: HandlebarsService, browserService: BrowserService, options: PuppeteerParameters, mjmlService?: MjmlService | undefined, pugService?: PugService | undefined, ejsService?: EjsService | undefined, nunjucksService?: NunjucksService | undefined);
|
|
109
125
|
private readonly limit;
|
|
110
126
|
generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array>;
|
|
111
127
|
generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
@@ -116,6 +132,8 @@ declare class PuppeteerService {
|
|
|
116
132
|
generatePdfFromPugFile(file: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
117
133
|
generatePdfFromEjsString(template: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
118
134
|
generatePdfFromEjsFile(file: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
135
|
+
generatePdfFromNunjucksString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
136
|
+
generatePdfFromNunjucksFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
119
137
|
}
|
|
120
138
|
|
|
121
139
|
declare class NestjsPdfService {
|
|
@@ -128,24 +146,6 @@ declare class NestjsPdfService {
|
|
|
128
146
|
* @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.
|
|
129
147
|
*/
|
|
130
148
|
generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
131
|
-
/**
|
|
132
|
-
* @deprecated Use the new method generatePdfFromTemplateHbsString
|
|
133
|
-
* @param template Handlebars template string
|
|
134
|
-
* @param parameters Data parameters to inject into the template
|
|
135
|
-
* @param options PDF generation options (optional)
|
|
136
|
-
* @returns PDF generated from the provided Handlebars template with parameters applied
|
|
137
|
-
* @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.
|
|
138
|
-
*/
|
|
139
|
-
generatePdfFromTemplateString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
140
|
-
/**
|
|
141
|
-
* @deprecated Use the new method generatePdfFromTemplateHbsFile
|
|
142
|
-
* @param file Path to the Handlebars template file
|
|
143
|
-
* @param parameters Data parameters to inject into the template
|
|
144
|
-
* @param options PDF generation options (optional)
|
|
145
|
-
* @returns PDF generated from the Handlebars template at the provided file path with parameters applied
|
|
146
|
-
* @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.
|
|
147
|
-
*/
|
|
148
|
-
generatePdfFromTemplateFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
149
149
|
/**
|
|
150
150
|
* @param template Handlebars template string
|
|
151
151
|
* @param parameters Data parameters to inject into the template
|
|
@@ -208,6 +208,22 @@ declare class NestjsPdfService {
|
|
|
208
208
|
* @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.
|
|
209
209
|
*/
|
|
210
210
|
generatePdfFromPugFile(file: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
211
|
+
/**
|
|
212
|
+
* @param template Nunjucks template string
|
|
213
|
+
* @param data Data to inject into the template
|
|
214
|
+
* @param options PDF generation options (optional)
|
|
215
|
+
* @returns PDF generated from the provided Nunjucks template with data applied
|
|
216
|
+
* @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.
|
|
217
|
+
*/
|
|
218
|
+
generatePdfFromNunjucksString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
219
|
+
/**
|
|
220
|
+
* @param file Path to the Nunjucks template file
|
|
221
|
+
* @param data Data to inject into the template
|
|
222
|
+
* @param options PDF generation options (optional)
|
|
223
|
+
* @returns PDF generated from the Nunjucks template at the provided file path with data applied
|
|
224
|
+
* @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
|
+
*/
|
|
226
|
+
generatePdfFromNunjucksFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
211
227
|
/**
|
|
212
228
|
* @param pdf The PDF bytes to modify
|
|
213
229
|
* @param fieldName The name of the signature field to add (default: 'SignatureDebtor')
|
|
@@ -257,4 +273,4 @@ declare class PuppeteerModule implements OnModuleInit {
|
|
|
257
273
|
*/
|
|
258
274
|
declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
|
|
259
275
|
|
|
260
|
-
export { type EjsOptions, EjsService, MjmlService, NestjsPdfModule, NestjsPdfService, type PdfLibModuleAsyncOptions, type PugOptions, PugService, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };
|
|
276
|
+
export { type EjsOptions, EjsService, MjmlService, NestjsPdfModule, NestjsPdfService, type NunjucksOptions, NunjucksService, type PdfLibModuleAsyncOptions, type PugOptions, PugService, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { Browser, BrowserContext, PDFOptions } from 'puppeteer';
|
|
|
6
6
|
import { MJMLParsingOptions } from 'mjml-core';
|
|
7
7
|
import pug, { LocalsObject } from 'pug';
|
|
8
8
|
import { Options, Data } from 'ejs';
|
|
9
|
+
import { ConfigureOptions } from 'nunjucks';
|
|
9
10
|
import { HandlebarsService } from '@gboutte/nestjs-hbs';
|
|
10
11
|
|
|
11
12
|
declare enum BrowserTag {
|
|
@@ -67,12 +68,26 @@ declare class EjsService {
|
|
|
67
68
|
renderFile(filePath: string, data?: Data, options?: EjsOptions): Promise<string>;
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
interface NunjucksOptions extends Partial<ConfigureOptions> {
|
|
72
|
+
noCache?: boolean;
|
|
73
|
+
watch?: boolean;
|
|
74
|
+
throwOnUndefined?: boolean;
|
|
75
|
+
trimBlocks?: boolean;
|
|
76
|
+
lstripBlocks?: boolean;
|
|
77
|
+
}
|
|
78
|
+
declare class NunjucksService {
|
|
79
|
+
constructor();
|
|
80
|
+
render(template: string, data?: Record<string, unknown>, options?: NunjucksOptions): string;
|
|
81
|
+
renderFile(filePath: string, data?: Record<string, unknown>, options?: NunjucksOptions): string;
|
|
82
|
+
}
|
|
83
|
+
|
|
70
84
|
interface PuppeteerParameters {
|
|
71
85
|
pdfOptions?: PDFOptions;
|
|
72
86
|
hbsOptions?: HandlebarsOptions;
|
|
73
87
|
mjmlOptions?: MJMLParsingOptions;
|
|
74
88
|
pugOptions?: PugOptions;
|
|
75
89
|
ejsOptions?: EjsOptions;
|
|
90
|
+
nunjucksOptions?: NunjucksOptions;
|
|
76
91
|
chromiumRevision?: string;
|
|
77
92
|
buildId?: string;
|
|
78
93
|
headless?: boolean | 'shell';
|
|
@@ -105,7 +120,8 @@ declare class PuppeteerService {
|
|
|
105
120
|
private readonly mjmlService?;
|
|
106
121
|
private readonly pugService?;
|
|
107
122
|
private readonly ejsService?;
|
|
108
|
-
|
|
123
|
+
private readonly nunjucksService?;
|
|
124
|
+
constructor(hbsService: HandlebarsService, browserService: BrowserService, options: PuppeteerParameters, mjmlService?: MjmlService | undefined, pugService?: PugService | undefined, ejsService?: EjsService | undefined, nunjucksService?: NunjucksService | undefined);
|
|
109
125
|
private readonly limit;
|
|
110
126
|
generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array>;
|
|
111
127
|
generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
@@ -116,6 +132,8 @@ declare class PuppeteerService {
|
|
|
116
132
|
generatePdfFromPugFile(file: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
117
133
|
generatePdfFromEjsString(template: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
118
134
|
generatePdfFromEjsFile(file: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
135
|
+
generatePdfFromNunjucksString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
136
|
+
generatePdfFromNunjucksFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
119
137
|
}
|
|
120
138
|
|
|
121
139
|
declare class NestjsPdfService {
|
|
@@ -128,24 +146,6 @@ declare class NestjsPdfService {
|
|
|
128
146
|
* @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.
|
|
129
147
|
*/
|
|
130
148
|
generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
131
|
-
/**
|
|
132
|
-
* @deprecated Use the new method generatePdfFromTemplateHbsString
|
|
133
|
-
* @param template Handlebars template string
|
|
134
|
-
* @param parameters Data parameters to inject into the template
|
|
135
|
-
* @param options PDF generation options (optional)
|
|
136
|
-
* @returns PDF generated from the provided Handlebars template with parameters applied
|
|
137
|
-
* @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.
|
|
138
|
-
*/
|
|
139
|
-
generatePdfFromTemplateString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
140
|
-
/**
|
|
141
|
-
* @deprecated Use the new method generatePdfFromTemplateHbsFile
|
|
142
|
-
* @param file Path to the Handlebars template file
|
|
143
|
-
* @param parameters Data parameters to inject into the template
|
|
144
|
-
* @param options PDF generation options (optional)
|
|
145
|
-
* @returns PDF generated from the Handlebars template at the provided file path with parameters applied
|
|
146
|
-
* @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.
|
|
147
|
-
*/
|
|
148
|
-
generatePdfFromTemplateFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
149
149
|
/**
|
|
150
150
|
* @param template Handlebars template string
|
|
151
151
|
* @param parameters Data parameters to inject into the template
|
|
@@ -208,6 +208,22 @@ declare class NestjsPdfService {
|
|
|
208
208
|
* @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.
|
|
209
209
|
*/
|
|
210
210
|
generatePdfFromPugFile(file: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
211
|
+
/**
|
|
212
|
+
* @param template Nunjucks template string
|
|
213
|
+
* @param data Data to inject into the template
|
|
214
|
+
* @param options PDF generation options (optional)
|
|
215
|
+
* @returns PDF generated from the provided Nunjucks template with data applied
|
|
216
|
+
* @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.
|
|
217
|
+
*/
|
|
218
|
+
generatePdfFromNunjucksString(template: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
219
|
+
/**
|
|
220
|
+
* @param file Path to the Nunjucks template file
|
|
221
|
+
* @param data Data to inject into the template
|
|
222
|
+
* @param options PDF generation options (optional)
|
|
223
|
+
* @returns PDF generated from the Nunjucks template at the provided file path with data applied
|
|
224
|
+
* @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
|
+
*/
|
|
226
|
+
generatePdfFromNunjucksFile(file: string, data?: Record<string, unknown>, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
|
|
211
227
|
/**
|
|
212
228
|
* @param pdf The PDF bytes to modify
|
|
213
229
|
* @param fieldName The name of the signature field to add (default: 'SignatureDebtor')
|
|
@@ -257,4 +273,4 @@ declare class PuppeteerModule implements OnModuleInit {
|
|
|
257
273
|
*/
|
|
258
274
|
declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
|
|
259
275
|
|
|
260
|
-
export { type EjsOptions, EjsService, MjmlService, NestjsPdfModule, NestjsPdfService, type PdfLibModuleAsyncOptions, type PugOptions, PugService, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };
|
|
276
|
+
export { type EjsOptions, EjsService, MjmlService, NestjsPdfModule, NestjsPdfService, type NunjucksOptions, NunjucksService, type PdfLibModuleAsyncOptions, type PugOptions, PugService, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };
|