pdfn 0.5.0 → 0.6.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 +34 -35
- package/package.json +4 -11
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# pdfn
|
|
2
2
|
|
|
3
|
-
CLI for pdfn. Dev server with live preview
|
|
4
|
-
|
|
5
|
-
> For serverless deployments, use [@sparticuz/chromium](https://github.com/Sparticuz/chromium) or a hosted browser service.
|
|
3
|
+
CLI for pdfn. Dev server with live preview and template scaffolding.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
@@ -21,21 +19,12 @@ npx pdfn dev # Start on port 3456
|
|
|
21
19
|
npx pdfn dev --open # Start and open browser
|
|
22
20
|
```
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
npx pdfn serve --port 8080 # Custom port
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
| Option | Env Variable | Default | Description |
|
|
34
|
-
|--------|--------------|---------|-------------|
|
|
35
|
-
| `--port` | `PDFN_PORT` | `3456` | Server port |
|
|
36
|
-
| `--mode` | - | `production` | Environment mode (loads .env.[mode]) |
|
|
37
|
-
|
|
38
|
-
Docker runs Gotenberg which handles PDF rendering with Chromium.
|
|
22
|
+
| Option | Default | Description |
|
|
23
|
+
|--------|---------|-------------|
|
|
24
|
+
| `--port` | `3456` | Server port |
|
|
25
|
+
| `--templates` | `./pdfn-templates` | Templates directory |
|
|
26
|
+
| `--open` | `false` | Open browser on start |
|
|
27
|
+
| `--no-open` | - | Don't open browser |
|
|
39
28
|
|
|
40
29
|
### `pdfn add`
|
|
41
30
|
|
|
@@ -56,34 +45,44 @@ npx pdfn add --list # Show all templates
|
|
|
56
45
|
| `poster` | Event poster (landscape) |
|
|
57
46
|
| `report` | Sales report with charts (requires recharts) |
|
|
58
47
|
|
|
59
|
-
##
|
|
48
|
+
## Production PDFs
|
|
60
49
|
|
|
61
|
-
|
|
50
|
+
For production PDF generation, choose based on your infrastructure:
|
|
62
51
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
# Form fields: files (index.html), waitForExpression, preferCssPageSize, printBackground
|
|
67
|
-
# Returns: application/pdf
|
|
52
|
+
**Option 1: Self-host with Puppeteer/Playwright**
|
|
53
|
+
|
|
54
|
+
Use `render()` to get print-ready HTML, then convert with your own browser:
|
|
68
55
|
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
```tsx
|
|
57
|
+
import { render } from '@pdfn/react';
|
|
58
|
+
import puppeteer from 'puppeteer';
|
|
59
|
+
|
|
60
|
+
const html = await render(<Invoice />);
|
|
61
|
+
|
|
62
|
+
const browser = await puppeteer.launch();
|
|
63
|
+
const page = await browser.newPage();
|
|
64
|
+
await page.setContent(html, { waitUntil: 'networkidle0' });
|
|
65
|
+
await page.waitForFunction(() => window.PDFN?.ready === true);
|
|
66
|
+
const pdf = await page.pdf({ preferCSSPageSize: true, printBackground: true });
|
|
67
|
+
await browser.close();
|
|
71
68
|
```
|
|
72
69
|
|
|
73
|
-
|
|
70
|
+
Works with Puppeteer, Playwright, Browserless, @sparticuz/chromium, or any Chromium setup.
|
|
74
71
|
|
|
75
|
-
|
|
72
|
+
**Option 2: pdfn Cloud**
|
|
76
73
|
|
|
77
|
-
|
|
74
|
+
Let pdfn manage the browser infrastructure:
|
|
78
75
|
|
|
79
|
-
```
|
|
80
|
-
import {
|
|
76
|
+
```tsx
|
|
77
|
+
import { generate } from '@pdfn/react';
|
|
81
78
|
|
|
82
|
-
|
|
83
|
-
await
|
|
79
|
+
// Set PDFN_API_KEY environment variable
|
|
80
|
+
const pdf = await generate(<Invoice />);
|
|
84
81
|
```
|
|
85
82
|
|
|
86
|
-
|
|
83
|
+
Get your API key at [console.pdfn.dev](https://console.pdfn.dev).
|
|
84
|
+
|
|
85
|
+
**Both produce identical PDFs** — same templates, same output.
|
|
87
86
|
|
|
88
87
|
## License
|
|
89
88
|
|
package/package.json
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdfn",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Dev server and PDF generation for print-ready PDFs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"pdfn": "./dist/cli.js"
|
|
8
8
|
},
|
|
9
|
-
"exports": {
|
|
10
|
-
"./server": {
|
|
11
|
-
"import": {
|
|
12
|
-
"types": "./dist/server/index.d.ts",
|
|
13
|
-
"default": "./dist/server/index.js"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
},
|
|
9
|
+
"exports": {},
|
|
17
10
|
"files": [
|
|
18
11
|
"dist",
|
|
19
12
|
"templates",
|
|
@@ -56,8 +49,8 @@
|
|
|
56
49
|
"vite": "^7.3.0",
|
|
57
50
|
"ws": "^8.18.3",
|
|
58
51
|
"@pdfn/client": "0.1.0",
|
|
59
|
-
"@pdfn/
|
|
60
|
-
"@pdfn/
|
|
52
|
+
"@pdfn/react": "0.5.0",
|
|
53
|
+
"@pdfn/vite": "0.5.1"
|
|
61
54
|
},
|
|
62
55
|
"devDependencies": {
|
|
63
56
|
"@types/express": "^5.0.6",
|