@shad0wz7/nestjs-pdf 1.0.0 → 1.0.2
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 +20 -20
- package/README.md +118 -122
- package/dist/chunk-DDRU76YD.mjs +39 -0
- package/dist/index.js +50869 -50779
- package/dist/index.mjs +82 -31539
- package/dist/pdf-KK3W2T5J.mjs +31514 -0
- package/package.json +7 -3
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
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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 (if published) 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
|
+
};
|