pdfn 0.4.6 → 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 +44 -83
- package/dist/cli.js +193 -270
- package/dist/cli.js.map +1 -1
- package/package.json +6 -11
- package/templates/inline/contract.tsx +1 -0
- package/templates/inline/invoice.tsx +1 -0
- package/templates/inline/letter.tsx +1 -0
- package/templates/inline/poster.tsx +1 -0
- package/templates/inline/report.tsx +1 -0
- package/templates/inline/ticket.tsx +1 -0
- package/templates/tailwind/contract.tsx +1 -0
- package/templates/tailwind/invoice.tsx +1 -0
- package/templates/tailwind/letter.tsx +1 -0
- package/templates/tailwind/poster.tsx +1 -0
- package/templates/tailwind/report.tsx +1 -0
- package/templates/tailwind/ticket.tsx +1 -0
package/README.md
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
# pdfn
|
|
2
2
|
|
|
3
|
-
CLI
|
|
4
|
-
|
|
5
|
-
> Requires headless Chromium. For serverless, use [@sparticuz/chromium](https://github.com/Sparticuz/chromium) or a hosted browser service.
|
|
6
|
-
|
|
7
|
-
## See It in Action
|
|
8
|
-
|
|
9
|
-
**[pdfn.dev](https://pdfn.dev/#preview)** — Interactive preview with example templates.
|
|
10
|
-
|
|
11
|
-
Or run locally: `npx pdfn dev --open`
|
|
3
|
+
CLI for pdfn. Dev server with live preview and template scaffolding.
|
|
12
4
|
|
|
13
5
|
## Installation
|
|
14
6
|
|
|
@@ -20,108 +12,77 @@ npm install -D pdfn
|
|
|
20
12
|
|
|
21
13
|
### `pdfn dev`
|
|
22
14
|
|
|
23
|
-
Development server with live preview and hot reload.
|
|
15
|
+
Development server with live preview and hot reload.
|
|
24
16
|
|
|
25
17
|
```bash
|
|
26
|
-
npx pdfn dev
|
|
27
|
-
npx pdfn dev --open
|
|
28
|
-
npx pdfn dev --port 4000 # Custom port
|
|
18
|
+
npx pdfn dev # Start on port 3456
|
|
19
|
+
npx pdfn dev --open # Start and open browser
|
|
29
20
|
```
|
|
30
21
|
|
|
31
22
|
| Option | Default | Description |
|
|
32
23
|
|--------|---------|-------------|
|
|
33
24
|
| `--port` | `3456` | Server port |
|
|
34
|
-
| `--
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
| `--templates` | `./pdfn-templates` | Templates directory |
|
|
26
|
+
| `--open` | `false` | Open browser on start |
|
|
27
|
+
| `--no-open` | - | Don't open browser |
|
|
37
28
|
|
|
38
|
-
|
|
39
|
-
- Auto-discovers templates in your templates directory
|
|
40
|
-
- Live preview UI with hot reload
|
|
41
|
-
- Performance metrics and debug overlays
|
|
42
|
-
- Exposes a local `/generate` endpoint for PDF generation
|
|
43
|
-
|
|
44
|
-
### `pdfn serve`
|
|
29
|
+
### `pdfn add`
|
|
45
30
|
|
|
46
|
-
|
|
31
|
+
Add starter templates to your project.
|
|
47
32
|
|
|
48
33
|
```bash
|
|
49
|
-
npx pdfn
|
|
50
|
-
npx pdfn
|
|
51
|
-
npx pdfn
|
|
34
|
+
npx pdfn add invoice # Add invoice template
|
|
35
|
+
npx pdfn add invoice --tailwind # With Tailwind classes
|
|
36
|
+
npx pdfn add --list # Show all templates
|
|
52
37
|
```
|
|
53
38
|
|
|
54
|
-
|
|
|
55
|
-
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
|
|
|
39
|
+
| Template | Description |
|
|
40
|
+
|----------|-------------|
|
|
41
|
+
| `invoice` | Professional invoice with itemized billing |
|
|
42
|
+
| `letter` | US business correspondence |
|
|
43
|
+
| `contract` | Legal service agreement |
|
|
44
|
+
| `ticket` | Event admission ticket |
|
|
45
|
+
| `poster` | Event poster (landscape) |
|
|
46
|
+
| `report` | Sales report with charts (requires recharts) |
|
|
59
47
|
|
|
60
|
-
|
|
48
|
+
## Production PDFs
|
|
61
49
|
|
|
62
|
-
|
|
50
|
+
For production PDF generation, choose based on your infrastructure:
|
|
63
51
|
|
|
64
|
-
|
|
65
|
-
npx pdfn add invoice # Add invoice template (inline styles)
|
|
66
|
-
npx pdfn add invoice --tailwind # Add with Tailwind classes
|
|
67
|
-
npx pdfn add letter # Add business letter
|
|
68
|
-
npx pdfn add contract # Add contract template
|
|
69
|
-
npx pdfn add ticket # Add event ticket
|
|
70
|
-
npx pdfn add poster # Add poster template
|
|
71
|
-
npx pdfn add --list # Show all templates
|
|
72
|
-
```
|
|
52
|
+
**Option 1: Self-host with Puppeteer/Playwright**
|
|
73
53
|
|
|
74
|
-
|
|
75
|
-
|--------|---------|-------------|
|
|
76
|
-
| `--inline` | ✓ | Use inline styles (default, no extra dependencies) |
|
|
77
|
-
| `--tailwind` | | Use Tailwind CSS classes (requires `@pdfn/tailwind`) |
|
|
78
|
-
| `--force` | | Overwrite existing files |
|
|
54
|
+
Use `render()` to get print-ready HTML, then convert with your own browser:
|
|
79
55
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
| `letter` | US business correspondence | Letter |
|
|
84
|
-
| `contract` | Legal service agreement | Legal |
|
|
85
|
-
| `ticket` | Event admission ticket | A5 |
|
|
86
|
-
| `poster` | Event poster (landscape) | Tabloid |
|
|
56
|
+
```tsx
|
|
57
|
+
import { render } from '@pdfn/react';
|
|
58
|
+
import puppeteer from 'puppeteer';
|
|
87
59
|
|
|
88
|
-
|
|
60
|
+
const html = await render(<Invoice />);
|
|
89
61
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
{
|
|
95
|
-
|
|
96
|
-
# Returns: application/pdf
|
|
97
|
-
|
|
98
|
-
# Health check
|
|
99
|
-
GET /health
|
|
100
|
-
# Returns: { "status": "ok", "browser": "connected", ... }
|
|
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();
|
|
101
68
|
```
|
|
102
69
|
|
|
103
|
-
|
|
70
|
+
Works with Puppeteer, Playwright, Browserless, @sparticuz/chromium, or any Chromium setup.
|
|
71
|
+
|
|
72
|
+
**Option 2: pdfn Cloud**
|
|
104
73
|
|
|
105
|
-
|
|
106
|
-
import { createServer } from 'pdfn/server';
|
|
74
|
+
Let pdfn manage the browser infrastructure:
|
|
107
75
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
maxConcurrent: 10,
|
|
111
|
-
timeout: 30000
|
|
112
|
-
});
|
|
76
|
+
```tsx
|
|
77
|
+
import { generate } from '@pdfn/react';
|
|
113
78
|
|
|
114
|
-
|
|
79
|
+
// Set PDFN_API_KEY environment variable
|
|
80
|
+
const pdf = await generate(<Invoice />);
|
|
115
81
|
```
|
|
116
82
|
|
|
117
|
-
|
|
83
|
+
Get your API key at [console.pdfn.dev](https://console.pdfn.dev).
|
|
118
84
|
|
|
119
|
-
|
|
120
|
-
|----------|---------|-------------|
|
|
121
|
-
| `PDFN_PORT` | `3456` | Server port |
|
|
122
|
-
| `PDFN_MAX_CONCURRENT` | `5` | Max concurrent PDF generations |
|
|
123
|
-
| `PDFN_TIMEOUT` | `30000` | Request timeout in ms |
|
|
124
|
-
| `DEBUG` | - | Set to `pdfn:cli` or `pdfn:*` to enable logging |
|
|
85
|
+
**Both produce identical PDFs** — same templates, same output.
|
|
125
86
|
|
|
126
87
|
## License
|
|
127
88
|
|