@shad0wz7/nestjs-pdf 1.0.0 → 1.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Emmanuel Boisset
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Emmanuel Boisset
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,122 +1,118 @@
1
- # nestjs-pdf
2
-
3
- A small NestJS library to generate and manipulate PDFs using Puppeteer and Handlebars.
4
-
5
- Main features:
6
- - Generate PDFs from HTML or Handlebars templates
7
- - Concurrency limiting for Puppeteer jobs (p-limit)
8
- - Add signature fields based on a text anchor in an existing PDF
9
- - Simple API (module + service) to integrate easily into a Nest application
10
-
11
- > Note: this repository contains the library source. To use it in another project you can either install it from npm (if published) or import the local package from the source.
12
-
13
- ## Installation
14
-
15
- In this repository:
16
-
17
- ```bash
18
- pnpm install
19
- ```
20
-
21
- To add the library to another project (example):
22
-
23
- ```bash
24
- npm install @shad0wz7/nestjs-pdf
25
- # or
26
- pnpm add @shad0wz7/nestjs-pdf
27
- # or
28
- yarn add @shad0wz7/nestjs-pdf
29
-
30
- # If using the local source, from the other project:
31
- pnpm add ../path/to/nestjs-pdf
32
- ```
33
-
34
- ## Quick start
35
-
36
- Import the module and configure it in your Nest application:
37
-
38
- ```ts
39
- import { Module } from '@nestjs/common';
40
- import { NestjsPdfModule } from 'nestjs-pdf';
41
-
42
- @Module({
43
- imports: [
44
- NestjsPdfModule.forRoot({
45
- // default Puppeteer / PDF options
46
- headless: true,
47
- pdfOptions: { format: 'A4' },
48
- }),
49
- ],
50
- })
51
- export class AppModule {}
52
- ```
53
-
54
- Inject the service and generate a PDF:
55
-
56
- ```ts
57
- import { Controller, Get } from '@nestjs/common';
58
- import { NestjsPdfService } from 'nestjs-pdf';
59
-
60
- @Controller()
61
- export class AppController {
62
- constructor(private readonly pdfService: NestjsPdfService) {}
63
-
64
- @Get('pdf')
65
- async getPdf() {
66
- const html = '<h1>Hello</h1><p>PDF generated by nestjs-pdf</p>';
67
- const buffer = await this.pdfService.generatePdfFromHtml(html);
68
- return buffer; // return a Buffer / Uint8Array depending on your controller
69
- }
70
- }
71
- ```
72
-
73
- Use a Handlebars template (string or file):
74
-
75
- ```ts
76
- const template = '<h1>{{title}}</h1><p>{{content}}</p>';
77
- const pdf = await pdfService.generatePdfFromTemplateString(template, { title: 'T', content: '...' });
78
- ```
79
-
80
- Add a signature field to an existing PDF (anchor-based):
81
-
82
- ```ts
83
- const originalPdfBytes = await this.pdfService.generatePdfFromHtml(html);
84
- const modifiedPdf = await pdfService.addSignatureFieldSignatureDebtorRaw(
85
- originalPdfBytes,
86
- 'SignatureDebtor',
87
- '__SIG_DEBTOR_ANCHOR__',
88
- );
89
- ```
90
-
91
- If the anchor is not found, the signature field will be added at a default position.
92
-
93
- ## Options and configuration
94
-
95
- The library exposes Puppeteer options via the `PuppeteerParameters` interface (see `src/puppeteer/puppeteer-parameters.interface.ts`). You can configure:
96
-
97
- - `headless` (boolean | 'shell')
98
- - `pdfOptions` (native Puppeteer options for `page.pdf`)
99
- - `extraPuppeteerArgs` (launch arguments for Chromium)
100
-
101
- You can use `forRootAsync(...)` if you need to provide configuration asynchronously.
102
-
103
- ## Tests
104
-
105
- This repository includes unit and integration tests (Jest). To run the tests:
106
-
107
- ```bash
108
- pnpm run test
109
- pnpm run test:e2e
110
- ```
111
-
112
- ## Contributing
113
-
114
- If you want to contribute:
115
-
116
- - Open an issue to discuss the change
117
- - Fork the repo, create a feature/fix branch, then open a PR
118
- - Follow Conventional Commits for automated releases
119
-
120
- ## License
121
-
122
- MIT — see the `LICENSE` file.
1
+ # nestjs-pdf
2
+
3
+ A small NestJS library to generate and manipulate PDFs using Puppeteer and Handlebars.
4
+
5
+ Main features:
6
+ - Generate PDFs from HTML or Handlebars templates
7
+ - Concurrency limiting for Puppeteer jobs (p-limit)
8
+ - Add signature fields based on a text anchor in an existing PDF
9
+ - Simple API (module and service) to integrate easily into a Nest application
10
+
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
+ ## Installation
14
+
15
+ To add the library inside your project :
16
+
17
+ ```bash
18
+ npm install @shad0wz7/nestjs-pdf
19
+ # or
20
+ pnpm add @shad0wz7/nestjs-pdf
21
+ # or
22
+ yarn add @shad0wz7/nestjs-pdf
23
+
24
+ # If using the local source, from the other project:
25
+ pnpm add ../path/to/nestjs-pdf
26
+ ```
27
+
28
+ ## Quick start
29
+
30
+ Import the module and configure it in your Nest application:
31
+
32
+ ```ts
33
+ import { Module } from '@nestjs/common';
34
+ import { NestjsPdfModule } from 'nestjs-pdf';
35
+
36
+ @Module({
37
+ imports: [
38
+ NestjsPdfModule.forRoot({
39
+ // default Puppeteer / PDF options
40
+ headless: true,
41
+ pdfOptions: { format: 'A4' },
42
+ }),
43
+ ],
44
+ })
45
+ export class AppModule {}
46
+ ```
47
+
48
+ Inject the service and generate a PDF:
49
+
50
+ ```ts
51
+ import { Controller, Get } from '@nestjs/common';
52
+ import { NestjsPdfService } from 'nestjs-pdf';
53
+
54
+ @Controller()
55
+ export class AppController {
56
+ constructor(private readonly pdfService: NestjsPdfService) {}
57
+
58
+ @Get('pdf')
59
+ async getPdf() {
60
+ const html = '<h1>Hello</h1><p>PDF generated by nestjs-pdf</p>';
61
+ const buffer = await this.pdfService.generatePdfFromHtml(html);
62
+ return buffer; // return a Buffer / Uint8Array depending on your controller
63
+ }
64
+ }
65
+ ```
66
+
67
+ Use a Handlebars template (string or file):
68
+
69
+ ```ts
70
+ const template = '<h1>{{title}}</h1><p>{{content}}</p>';
71
+ const pdf = await pdfService.generatePdfFromTemplateString(template, { title: 'T', content: '...' });
72
+ ```
73
+
74
+ Add a signature field to an existing PDF (anchor-based):
75
+
76
+ ```ts
77
+ const originalPdfBytes = await this.pdfService.generatePdfFromHtml(html);
78
+ const modifiedPdf = await pdfService.addSignatureFieldSignatureDebtorRaw(
79
+ originalPdfBytes,
80
+ 'SignatureDebtor',
81
+ '__SIG_DEBTOR_ANCHOR__',
82
+ );
83
+ ```
84
+
85
+ If the anchor is not found, the signature field will be added at a default position.
86
+
87
+ **Warning:** if you encounter issues like "Failed to load pdfjs-dist." Make sure to install `@napi-rs/canvas` as a dependency in your project, as it's required by the library for PDF manipulation.
88
+
89
+ ## Options and configuration
90
+
91
+ The library exposes Puppeteer options via the `PuppeteerParameters` interface (see `src/puppeteer/puppeteer-parameters.interface.ts`). You can configure:
92
+
93
+ - `headless` (boolean | 'shell')
94
+ - `pdfOptions` (native Puppeteer options for `page.pdf`)
95
+ - `extraPuppeteerArgs` (launch arguments for Chromium)
96
+
97
+ You can use `forRootAsync(...)` if you need to provide configuration asynchronously.
98
+
99
+ ## Tests
100
+
101
+ This repository includes unit and integration tests (Jest). To run the tests:
102
+
103
+ ```bash
104
+ pnpm run test
105
+ pnpm run test:e2e
106
+ ```
107
+
108
+ ## Contributing
109
+
110
+ If you want to contribute:
111
+
112
+ - Open an issue to discuss the change
113
+ - Fork the repo, create a feature/fix branch, then open a PR
114
+ - Follow Conventional Commits for automated releases
115
+
116
+ ## License
117
+
118
+ MIT — see the `LICENSE` file.
@@ -0,0 +1,39 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
+ }) : x)(function(x) {
11
+ if (typeof require !== "undefined") return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+
34
+ export {
35
+ __name,
36
+ __require,
37
+ __commonJS,
38
+ __toESM
39
+ };
package/dist/index.d.mts CHANGED
@@ -116,4 +116,6 @@ declare class PuppeteerHandlebarsModule {
116
116
  static forRootAsync(options: PuppeteerHandlebarsModuleAsyncOptions): DynamicModule;
117
117
  }
118
118
 
119
- export { NestjsPdfModule, NestjsPdfService, type PdfLibModuleAsyncOptions, PuppeteerHandlebarsModule, type PuppeteerHandlebarsModuleAsyncOptions, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService };
119
+ declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
120
+
121
+ export { NestjsPdfModule, NestjsPdfService, type PdfLibModuleAsyncOptions, PuppeteerHandlebarsModule, type PuppeteerHandlebarsModuleAsyncOptions, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };
package/dist/index.d.ts CHANGED
@@ -116,4 +116,6 @@ declare class PuppeteerHandlebarsModule {
116
116
  static forRootAsync(options: PuppeteerHandlebarsModuleAsyncOptions): DynamicModule;
117
117
  }
118
118
 
119
- export { NestjsPdfModule, NestjsPdfService, type PdfLibModuleAsyncOptions, PuppeteerHandlebarsModule, type PuppeteerHandlebarsModuleAsyncOptions, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService };
119
+ declare function getRelativePathToValue(moduleDir: string, relativeToModule: string): string;
120
+
121
+ export { NestjsPdfModule, NestjsPdfService, type PdfLibModuleAsyncOptions, PuppeteerHandlebarsModule, type PuppeteerHandlebarsModuleAsyncOptions, PuppeteerModule, type PuppeteerModuleAsyncOptions, type PuppeteerParameters, PuppeteerService, getRelativePathToValue };