@shad0wz7/nestjs-pdf 1.1.0 → 1.1.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/dist/index.d.mts CHANGED
@@ -87,9 +87,51 @@ declare class PuppeteerService {
87
87
  declare class NestjsPdfService {
88
88
  private readonly puppeteerService;
89
89
  constructor(puppeteerService: PuppeteerService);
90
+ /**
91
+ * @param html HTML string to convert to PDF
92
+ * @param options PDF generation options (optional)
93
+ * @returns PDF generated from the provided HTML
94
+ * @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.
95
+ */
90
96
  generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
97
+ /**
98
+ * @param template Handlebars template string
99
+ * @param parameters Data parameters to inject into the template
100
+ * @param options PDF generation options (optional)
101
+ * @returns PDF generated from the provided Handlebars template with parameters applied
102
+ * @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.
103
+ */
91
104
  generatePdfFromTemplateString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
105
+ /**
106
+ * @param file Path to the Handlebars template file
107
+ * @param parameters Data parameters to inject into the template
108
+ * @param options PDF generation options (optional)
109
+ * @returns PDF generated from the Handlebars template at the provided file path with parameters applied
110
+ * @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.
111
+ */
92
112
  generatePdfFromTemplateFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
113
+ /**
114
+ * @param pdf The PDF bytes to modify
115
+ * @param fieldName The name of the signature field to add (default: 'SignatureDebtor')
116
+ * @param anchorText The text anchor to locate the signature field position (default: '__SIG_DEBTOR_ANCHOR__')
117
+ * @returns Modified PDF with a signature field added at the anchor position
118
+ * @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`.
119
+ *
120
+ * Usage example:
121
+ * ```typescript
122
+ * const modifiedPdf = await pdfService.addSignatureFieldSignatureDebtorRaw(
123
+ * originalPdfBytes,
124
+ * 'SignatureDebtor',
125
+ * '__SIG_DEBTOR_ANCHOR__'
126
+ * );
127
+ * ```
128
+ *
129
+ * 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.
130
+ *
131
+ * If the anchor is not found, the signature field will be added at a default position (centered at the bottom of the last page).
132
+ *
133
+ * 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.
134
+ */
93
135
  addSignatureFieldSignatureDebtorRaw(pdf: Uint8Array | Buffer, fieldName?: string, anchorText?: string): Promise<Uint8Array<ArrayBufferLike>>;
94
136
  }
95
137
 
@@ -116,6 +158,15 @@ declare class PuppeteerHandlebarsModule {
116
158
  static forRootAsync(options: PuppeteerHandlebarsModuleAsyncOptions): DynamicModule;
117
159
  }
118
160
 
161
+ /**
162
+ * Get the relative path to a value from the module directory.
163
+ * @param moduleDir the path of the module, typically __dirname
164
+ * @param relativeToModule the path to the value relative to the module directory
165
+ * @returns the relative path from the current working directory to the value
166
+ * @example
167
+ * getRelativePathToValue(__dirname, './templates/my-template.hbs');
168
+ * // returns 'context/pdf/templates/my-template.hbs' if the current working directory is '/
169
+ */
119
170
  declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
120
171
 
121
172
  export { NestjsPdfModule, NestjsPdfService, type PdfLibModuleAsyncOptions, PuppeteerHandlebarsModule, type PuppeteerHandlebarsModuleAsyncOptions, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };
package/dist/index.d.ts CHANGED
@@ -87,9 +87,51 @@ declare class PuppeteerService {
87
87
  declare class NestjsPdfService {
88
88
  private readonly puppeteerService;
89
89
  constructor(puppeteerService: PuppeteerService);
90
+ /**
91
+ * @param html HTML string to convert to PDF
92
+ * @param options PDF generation options (optional)
93
+ * @returns PDF generated from the provided HTML
94
+ * @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.
95
+ */
90
96
  generatePdfFromHtml(html: string, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
97
+ /**
98
+ * @param template Handlebars template string
99
+ * @param parameters Data parameters to inject into the template
100
+ * @param options PDF generation options (optional)
101
+ * @returns PDF generated from the provided Handlebars template with parameters applied
102
+ * @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.
103
+ */
91
104
  generatePdfFromTemplateString(template: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
105
+ /**
106
+ * @param file Path to the Handlebars template file
107
+ * @param parameters Data parameters to inject into the template
108
+ * @param options PDF generation options (optional)
109
+ * @returns PDF generated from the Handlebars template at the provided file path with parameters applied
110
+ * @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.
111
+ */
92
112
  generatePdfFromTemplateFile(file: string, parameters?: any, options?: PuppeteerParameters): Promise<Uint8Array<ArrayBufferLike>>;
113
+ /**
114
+ * @param pdf The PDF bytes to modify
115
+ * @param fieldName The name of the signature field to add (default: 'SignatureDebtor')
116
+ * @param anchorText The text anchor to locate the signature field position (default: '__SIG_DEBTOR_ANCHOR__')
117
+ * @returns Modified PDF with a signature field added at the anchor position
118
+ * @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`.
119
+ *
120
+ * Usage example:
121
+ * ```typescript
122
+ * const modifiedPdf = await pdfService.addSignatureFieldSignatureDebtorRaw(
123
+ * originalPdfBytes,
124
+ * 'SignatureDebtor',
125
+ * '__SIG_DEBTOR_ANCHOR__'
126
+ * );
127
+ * ```
128
+ *
129
+ * 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.
130
+ *
131
+ * If the anchor is not found, the signature field will be added at a default position (centered at the bottom of the last page).
132
+ *
133
+ * 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.
134
+ */
93
135
  addSignatureFieldSignatureDebtorRaw(pdf: Uint8Array | Buffer, fieldName?: string, anchorText?: string): Promise<Uint8Array<ArrayBufferLike>>;
94
136
  }
95
137
 
@@ -116,6 +158,15 @@ declare class PuppeteerHandlebarsModule {
116
158
  static forRootAsync(options: PuppeteerHandlebarsModuleAsyncOptions): DynamicModule;
117
159
  }
118
160
 
161
+ /**
162
+ * Get the relative path to a value from the module directory.
163
+ * @param moduleDir the path of the module, typically __dirname
164
+ * @param relativeToModule the path to the value relative to the module directory
165
+ * @returns the relative path from the current working directory to the value
166
+ * @example
167
+ * getRelativePathToValue(__dirname, './templates/my-template.hbs');
168
+ * // returns 'context/pdf/templates/my-template.hbs' if the current working directory is '/
169
+ */
119
170
  declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
120
171
 
121
172
  export { NestjsPdfModule, NestjsPdfService, type PdfLibModuleAsyncOptions, PuppeteerHandlebarsModule, type PuppeteerHandlebarsModuleAsyncOptions, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };