@shad0wz7/nestjs-pdf 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # nestjs-pdf
2
2
 
3
- A small NestJS library to generate and manipulate PDFs using Puppeteer and Handlebars.
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
- - Generate PDFs from HTML or Handlebars templates
6
+ - Generate PDFs from HTML, Handlebars, EJS, Pug or MJML templates
7
7
  - Concurrency limiting for Puppeteer jobs (p-limit)
8
8
  - Add signature fields based on a text anchor in an existing PDF
9
9
  - Simple API (module and service) to integrate easily into a Nest application
@@ -68,7 +68,11 @@ Use a Handlebars template (string or file):
68
68
 
69
69
  ```ts
70
70
  const template = '<h1>{{title}}</h1><p>{{content}}</p>';
71
- const pdf = await pdfService.generatePdfFromTemplateString(template, { title: 'T', content: '...' });
71
+ const pdf = await pdfService.generatePdfFromTemplateHbsString(template, { title: 'T', content: '...' });
72
+ ```
73
+
74
+ ```ts
75
+ const pdf = await pdfService.generatePdfFromTemplateHbsFile(filePath, { title: 'T', content: '...' });
72
76
  ```
73
77
 
74
78
  Add a signature field to an existing PDF (anchor-based):
package/dist/index.d.mts CHANGED
@@ -3,6 +3,9 @@ import { HandlebarsOptions } from '@gboutte/nestjs-hbs/dist/handlebars-options.i
3
3
  import * as puppeteerBrowser from '@puppeteer/browsers';
4
4
  import { Browser as Browser$1 } from '@puppeteer/browsers';
5
5
  import { Browser, BrowserContext, PDFOptions } from 'puppeteer';
6
+ import { MJMLParsingOptions } from 'mjml-core';
7
+ import pug, { LocalsObject } from 'pug';
8
+ import { Options, Data } from 'ejs';
6
9
  import { HandlebarsService } from '@gboutte/nestjs-hbs';
7
10
 
8
11
  declare enum BrowserTag {
@@ -50,9 +53,26 @@ declare class BrowserService implements OnModuleDestroy {
50
53
  getLockedBuildId(browser: Browser$1): string | null;
51
54
  }
52
55
 
56
+ type PugOptions = pug.Options;
57
+ declare class PugService {
58
+ render(template: string, data?: pug.LocalsObject, options?: PugOptions): string;
59
+ renderFile(filePath: string, data?: pug.LocalsObject, options?: PugOptions): string;
60
+ }
61
+
62
+ interface EjsOptions extends Omit<Options, 'async'> {
63
+ async?: boolean;
64
+ }
65
+ declare class EjsService {
66
+ render(template: string, data?: Data, options?: EjsOptions): Promise<string>;
67
+ renderFile(filePath: string, data?: Data, options?: EjsOptions): Promise<string>;
68
+ }
69
+
53
70
  interface PuppeteerParameters {
54
71
  pdfOptions?: PDFOptions;
55
72
  hbsOptions?: HandlebarsOptions;
73
+ mjmlOptions?: MJMLParsingOptions;
74
+ pugOptions?: PugOptions;
75
+ ejsOptions?: EjsOptions;
56
76
  chromiumRevision?: string;
57
77
  buildId?: string;
58
78
  headless?: boolean | 'shell';
@@ -73,23 +93,143 @@ declare class NestjsPdfModule {
73
93
  static forRootAsync(options: PdfLibModuleAsyncOptions): DynamicModule;
74
94
  }
75
95
 
96
+ declare class MjmlService {
97
+ render(template: string, options?: MJMLParsingOptions): Promise<string>;
98
+ renderFile(filePath: string, options?: MJMLParsingOptions): Promise<string>;
99
+ }
100
+
76
101
  declare class PuppeteerService {
77
102
  private readonly hbsService;
78
103
  private readonly browserService;
79
104
  private readonly options;
80
- constructor(hbsService: HandlebarsService, browserService: BrowserService, options: PuppeteerParameters);
105
+ private readonly mjmlService?;
106
+ private readonly pugService?;
107
+ private readonly ejsService?;
108
+ constructor(hbsService: HandlebarsService, browserService: BrowserService, options: PuppeteerParameters, mjmlService?: MjmlService | undefined, pugService?: PugService | undefined, ejsService?: EjsService | undefined);
81
109
  private readonly limit;
82
110
  generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array>;
83
- generatePdfFromTemplateString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
84
- generatePdfFromTemplateFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
111
+ generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
112
+ generatePdfFromTemplateHbsFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
113
+ generatePdfFromMjmlString(template: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
114
+ generatePdfFromMjmlFile(file: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
115
+ generatePdfFromPugString(template: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
116
+ generatePdfFromPugFile(file: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
117
+ generatePdfFromEjsString(template: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
118
+ generatePdfFromEjsFile(file: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
85
119
  }
86
120
 
87
121
  declare class NestjsPdfService {
88
122
  private readonly puppeteerService;
89
123
  constructor(puppeteerService: PuppeteerService);
124
+ /**
125
+ * @param html HTML string to convert to PDF
126
+ * @param options PDF generation options (optional)
127
+ * @returns PDF generated from the provided HTML
128
+ * @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
+ */
90
130
  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
+ */
91
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
+ */
92
148
  generatePdfFromTemplateFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
149
+ /**
150
+ * @param template Handlebars template string
151
+ * @param parameters Data parameters to inject into the template
152
+ * @param options PDF generation options (optional)
153
+ * @returns PDF generated from the provided Handlebars template with parameters applied
154
+ * @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.
155
+ */
156
+ generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
157
+ /**
158
+ * @param file Path to the Handlebars template file
159
+ * @param parameters Data parameters to inject into the template
160
+ * @param options PDF generation options (optional)
161
+ * @returns PDF generated from the Handlebars template at the provided file path with parameters applied
162
+ * @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.
163
+ */
164
+ generatePdfFromTemplateHbsFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
165
+ /**
166
+ * @param template MJML template string
167
+ * @param options PDF generation options (optional)
168
+ * @returns PDF generated from the provided MJML template
169
+ * @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.
170
+ */
171
+ generatePdfFromMjmlString(template: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
172
+ /**
173
+ * @param file Path to the MJML template file
174
+ * @param options PDF generation options (optional)
175
+ * @returns PDF generated from the MJML template at the provided file path
176
+ * @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.
177
+ */
178
+ generatePdfFromMjmlFile(file: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
179
+ /**
180
+ * @param template EJS template string
181
+ * @param data Data to inject into the template
182
+ * @param options PDF generation options (optional)
183
+ * @returns PDF generated from the provided EJS template with data applied
184
+ * @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.
185
+ */
186
+ generatePdfFromEjsString(template: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
187
+ /**
188
+ * @param file Path to the EJS template file
189
+ * @param data Data to inject into the template
190
+ * @param options PDF generation options (optional)
191
+ * @returns PDF generated from the EJS template at the provided file path with data applied
192
+ * @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.
193
+ */
194
+ generatePdfFromEjsFile(file: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
195
+ /**
196
+ * @param template Pug template string
197
+ * @param data Data to inject into the template
198
+ * @param options PDF generation options (optional)
199
+ * @returns PDF generated from the provided Pug template with data applied
200
+ * @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.
201
+ */
202
+ generatePdfFromPugString(template: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
203
+ /**
204
+ * @param file Path to the Pug template file
205
+ * @param data Data to inject into the template
206
+ * @param options PDF generation options (optional)
207
+ * @returns PDF generated from the Pug template at the provided file path with data applied
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
+ */
210
+ generatePdfFromPugFile(file: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
211
+ /**
212
+ * @param pdf The PDF bytes to modify
213
+ * @param fieldName The name of the signature field to add (default: 'SignatureDebtor')
214
+ * @param anchorText The text anchor to locate the signature field position (default: '__SIG_DEBTOR_ANCHOR__')
215
+ * @returns Modified PDF with a signature field added at the anchor position
216
+ * @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`.
217
+ *
218
+ * Usage example:
219
+ * ```typescript
220
+ * const modifiedPdf = await pdfService.addSignatureFieldSignatureDebtorRaw(
221
+ * originalPdfBytes,
222
+ * 'SignatureDebtor',
223
+ * '__SIG_DEBTOR_ANCHOR__'
224
+ * );
225
+ * ```
226
+ *
227
+ * 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.
228
+ *
229
+ * If the anchor is not found, the signature field will be added at a default position (centered at the bottom of the last page).
230
+ *
231
+ * 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.
232
+ */
93
233
  addSignatureFieldSignatureDebtorRaw(pdf: Uint8Array | Buffer, fieldName?: string, anchorText?: string): Promise<Uint8Array<ArrayBufferLike>>;
94
234
  }
95
235
 
@@ -106,16 +246,15 @@ declare class PuppeteerModule implements OnModuleInit {
106
246
  static forRootAsync(options: PuppeteerModuleAsyncOptions): DynamicModule;
107
247
  }
108
248
 
109
- interface PuppeteerHandlebarsModuleAsyncOptions {
110
- imports?: DynamicModule[];
111
- inject?: (InjectionToken | OptionalFactoryDependency)[];
112
- useFactory: (...args: unknown[]) => Promise<HandlebarsOptions> | HandlebarsOptions;
113
- }
114
- declare class PuppeteerHandlebarsModule {
115
- static forRoot(handlebarsOptions: HandlebarsOptions): DynamicModule;
116
- static forRootAsync(options: PuppeteerHandlebarsModuleAsyncOptions): DynamicModule;
117
- }
118
-
249
+ /**
250
+ * Get the relative path to a value from the module directory.
251
+ * @param moduleDir the path of the module, typically __dirname
252
+ * @param relativeToModule the path to the value relative to the module directory
253
+ * @returns the relative path from the current working directory to the value
254
+ * @example
255
+ * getRelativePathToValue(__dirname, './templates/my-template.hbs');
256
+ * // returns 'context/pdf/templates/my-template.hbs' if the current working directory is '/
257
+ */
119
258
  declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
120
259
 
121
- export { NestjsPdfModule, NestjsPdfService, type PdfLibModuleAsyncOptions, PuppeteerHandlebarsModule, type PuppeteerHandlebarsModuleAsyncOptions, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };
260
+ export { type EjsOptions, EjsService, MjmlService, NestjsPdfModule, NestjsPdfService, type PdfLibModuleAsyncOptions, type PugOptions, PugService, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,9 @@ import { HandlebarsOptions } from '@gboutte/nestjs-hbs/dist/handlebars-options.i
3
3
  import * as puppeteerBrowser from '@puppeteer/browsers';
4
4
  import { Browser as Browser$1 } from '@puppeteer/browsers';
5
5
  import { Browser, BrowserContext, PDFOptions } from 'puppeteer';
6
+ import { MJMLParsingOptions } from 'mjml-core';
7
+ import pug, { LocalsObject } from 'pug';
8
+ import { Options, Data } from 'ejs';
6
9
  import { HandlebarsService } from '@gboutte/nestjs-hbs';
7
10
 
8
11
  declare enum BrowserTag {
@@ -50,9 +53,26 @@ declare class BrowserService implements OnModuleDestroy {
50
53
  getLockedBuildId(browser: Browser$1): string | null;
51
54
  }
52
55
 
56
+ type PugOptions = pug.Options;
57
+ declare class PugService {
58
+ render(template: string, data?: pug.LocalsObject, options?: PugOptions): string;
59
+ renderFile(filePath: string, data?: pug.LocalsObject, options?: PugOptions): string;
60
+ }
61
+
62
+ interface EjsOptions extends Omit<Options, 'async'> {
63
+ async?: boolean;
64
+ }
65
+ declare class EjsService {
66
+ render(template: string, data?: Data, options?: EjsOptions): Promise<string>;
67
+ renderFile(filePath: string, data?: Data, options?: EjsOptions): Promise<string>;
68
+ }
69
+
53
70
  interface PuppeteerParameters {
54
71
  pdfOptions?: PDFOptions;
55
72
  hbsOptions?: HandlebarsOptions;
73
+ mjmlOptions?: MJMLParsingOptions;
74
+ pugOptions?: PugOptions;
75
+ ejsOptions?: EjsOptions;
56
76
  chromiumRevision?: string;
57
77
  buildId?: string;
58
78
  headless?: boolean | 'shell';
@@ -73,23 +93,143 @@ declare class NestjsPdfModule {
73
93
  static forRootAsync(options: PdfLibModuleAsyncOptions): DynamicModule;
74
94
  }
75
95
 
96
+ declare class MjmlService {
97
+ render(template: string, options?: MJMLParsingOptions): Promise<string>;
98
+ renderFile(filePath: string, options?: MJMLParsingOptions): Promise<string>;
99
+ }
100
+
76
101
  declare class PuppeteerService {
77
102
  private readonly hbsService;
78
103
  private readonly browserService;
79
104
  private readonly options;
80
- constructor(hbsService: HandlebarsService, browserService: BrowserService, options: PuppeteerParameters);
105
+ private readonly mjmlService?;
106
+ private readonly pugService?;
107
+ private readonly ejsService?;
108
+ constructor(hbsService: HandlebarsService, browserService: BrowserService, options: PuppeteerParameters, mjmlService?: MjmlService | undefined, pugService?: PugService | undefined, ejsService?: EjsService | undefined);
81
109
  private readonly limit;
82
110
  generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array>;
83
- generatePdfFromTemplateString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
84
- generatePdfFromTemplateFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
111
+ generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
112
+ generatePdfFromTemplateHbsFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
113
+ generatePdfFromMjmlString(template: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
114
+ generatePdfFromMjmlFile(file: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
115
+ generatePdfFromPugString(template: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
116
+ generatePdfFromPugFile(file: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
117
+ generatePdfFromEjsString(template: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
118
+ generatePdfFromEjsFile(file: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
85
119
  }
86
120
 
87
121
  declare class NestjsPdfService {
88
122
  private readonly puppeteerService;
89
123
  constructor(puppeteerService: PuppeteerService);
124
+ /**
125
+ * @param html HTML string to convert to PDF
126
+ * @param options PDF generation options (optional)
127
+ * @returns PDF generated from the provided HTML
128
+ * @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
+ */
90
130
  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
+ */
91
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
+ */
92
148
  generatePdfFromTemplateFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
149
+ /**
150
+ * @param template Handlebars template string
151
+ * @param parameters Data parameters to inject into the template
152
+ * @param options PDF generation options (optional)
153
+ * @returns PDF generated from the provided Handlebars template with parameters applied
154
+ * @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.
155
+ */
156
+ generatePdfFromTemplateHbsString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
157
+ /**
158
+ * @param file Path to the Handlebars template file
159
+ * @param parameters Data parameters to inject into the template
160
+ * @param options PDF generation options (optional)
161
+ * @returns PDF generated from the Handlebars template at the provided file path with parameters applied
162
+ * @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.
163
+ */
164
+ generatePdfFromTemplateHbsFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
165
+ /**
166
+ * @param template MJML template string
167
+ * @param options PDF generation options (optional)
168
+ * @returns PDF generated from the provided MJML template
169
+ * @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.
170
+ */
171
+ generatePdfFromMjmlString(template: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
172
+ /**
173
+ * @param file Path to the MJML template file
174
+ * @param options PDF generation options (optional)
175
+ * @returns PDF generated from the MJML template at the provided file path
176
+ * @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.
177
+ */
178
+ generatePdfFromMjmlFile(file: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
179
+ /**
180
+ * @param template EJS template string
181
+ * @param data Data to inject into the template
182
+ * @param options PDF generation options (optional)
183
+ * @returns PDF generated from the provided EJS template with data applied
184
+ * @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.
185
+ */
186
+ generatePdfFromEjsString(template: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
187
+ /**
188
+ * @param file Path to the EJS template file
189
+ * @param data Data to inject into the template
190
+ * @param options PDF generation options (optional)
191
+ * @returns PDF generated from the EJS template at the provided file path with data applied
192
+ * @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.
193
+ */
194
+ generatePdfFromEjsFile(file: string, data?: Data, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
195
+ /**
196
+ * @param template Pug template string
197
+ * @param data Data to inject into the template
198
+ * @param options PDF generation options (optional)
199
+ * @returns PDF generated from the provided Pug template with data applied
200
+ * @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.
201
+ */
202
+ generatePdfFromPugString(template: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
203
+ /**
204
+ * @param file Path to the Pug template file
205
+ * @param data Data to inject into the template
206
+ * @param options PDF generation options (optional)
207
+ * @returns PDF generated from the Pug template at the provided file path with data applied
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
+ */
210
+ generatePdfFromPugFile(file: string, data?: LocalsObject, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
211
+ /**
212
+ * @param pdf The PDF bytes to modify
213
+ * @param fieldName The name of the signature field to add (default: 'SignatureDebtor')
214
+ * @param anchorText The text anchor to locate the signature field position (default: '__SIG_DEBTOR_ANCHOR__')
215
+ * @returns Modified PDF with a signature field added at the anchor position
216
+ * @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`.
217
+ *
218
+ * Usage example:
219
+ * ```typescript
220
+ * const modifiedPdf = await pdfService.addSignatureFieldSignatureDebtorRaw(
221
+ * originalPdfBytes,
222
+ * 'SignatureDebtor',
223
+ * '__SIG_DEBTOR_ANCHOR__'
224
+ * );
225
+ * ```
226
+ *
227
+ * 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.
228
+ *
229
+ * If the anchor is not found, the signature field will be added at a default position (centered at the bottom of the last page).
230
+ *
231
+ * 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.
232
+ */
93
233
  addSignatureFieldSignatureDebtorRaw(pdf: Uint8Array | Buffer, fieldName?: string, anchorText?: string): Promise<Uint8Array<ArrayBufferLike>>;
94
234
  }
95
235
 
@@ -106,16 +246,15 @@ declare class PuppeteerModule implements OnModuleInit {
106
246
  static forRootAsync(options: PuppeteerModuleAsyncOptions): DynamicModule;
107
247
  }
108
248
 
109
- interface PuppeteerHandlebarsModuleAsyncOptions {
110
- imports?: DynamicModule[];
111
- inject?: (InjectionToken | OptionalFactoryDependency)[];
112
- useFactory: (...args: unknown[]) => Promise<HandlebarsOptions> | HandlebarsOptions;
113
- }
114
- declare class PuppeteerHandlebarsModule {
115
- static forRoot(handlebarsOptions: HandlebarsOptions): DynamicModule;
116
- static forRootAsync(options: PuppeteerHandlebarsModuleAsyncOptions): DynamicModule;
117
- }
118
-
249
+ /**
250
+ * Get the relative path to a value from the module directory.
251
+ * @param moduleDir the path of the module, typically __dirname
252
+ * @param relativeToModule the path to the value relative to the module directory
253
+ * @returns the relative path from the current working directory to the value
254
+ * @example
255
+ * getRelativePathToValue(__dirname, './templates/my-template.hbs');
256
+ * // returns 'context/pdf/templates/my-template.hbs' if the current working directory is '/
257
+ */
119
258
  declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
120
259
 
121
- export { NestjsPdfModule, NestjsPdfService, type PdfLibModuleAsyncOptions, PuppeteerHandlebarsModule, type PuppeteerHandlebarsModuleAsyncOptions, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };
260
+ export { type EjsOptions, EjsService, MjmlService, NestjsPdfModule, NestjsPdfService, type PdfLibModuleAsyncOptions, type PugOptions, PugService, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };