pdfn 0.8.2 → 0.8.3
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 +24 -92
- package/dist/cli.js +2 -1476
- package/dist/cli.js.map +1 -1
- package/package.json +11 -9
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# pdfn
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Dev server and CLI for pdfn.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -12,123 +12,55 @@ npm install -D pdfn
|
|
|
12
12
|
|
|
13
13
|
### `pdfn dev`
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Start dev server with live preview:
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
18
|
npx pdfn dev # Start on port 3456
|
|
19
|
-
npx pdfn dev --open #
|
|
19
|
+
npx pdfn dev --open # Open browser automatically
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
Options:
|
|
23
|
+
|
|
24
|
+
| Flag | Default | Description |
|
|
25
|
+
|------|---------|-------------|
|
|
24
26
|
| `--port` | `3456` | Server port |
|
|
25
27
|
| `--templates` | `./pdfn-templates` | Templates directory |
|
|
26
28
|
| `--open` | `false` | Open browser on start |
|
|
27
|
-
| `--no-open` | - | Don't open browser |
|
|
28
|
-
|
|
29
|
-
**Dev Server Features:**
|
|
30
|
-
|
|
31
|
-
- Live preview with hot reload
|
|
32
|
-
- Inspector panel (performance, debug overlays)
|
|
33
|
-
- Accessibility checker (axe-core)
|
|
34
|
-
- PDF/A compliance dropdown
|
|
35
|
-
|
|
36
|
-
**PDF/A Compliance:**
|
|
37
|
-
|
|
38
|
-
| Standard | Description |
|
|
39
|
-
|----------|-------------|
|
|
40
|
-
| PDF/A-1b | Basic PDF 1.4 archival (most compatible) |
|
|
41
|
-
| PDF/A-2b | PDF 1.7 archival, allows transparency |
|
|
42
|
-
| PDF/A-3b | Like PDF/A-2b plus embedded files |
|
|
43
|
-
|
|
44
|
-
> `pdfn dev` focuses on layout preview. PDF/A archival compliance (validation, metadata, color profiles) is applied by pdfn Cloud as post-processing.
|
|
45
|
-
>
|
|
46
|
-
> **Layout is identical** whether you use pdfn dev, pdfn Cloud, or self-host. Compliance does not change layout — it only adds validation and archival metadata.
|
|
47
|
-
|
|
48
|
-
To generate PDF/A-compliant PDFs, set `PDFN_API_KEY`. Without an API key, requests with a standard will fail.
|
|
49
|
-
|
|
50
|
-
**Server API:**
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
POST /v1/generate # HTML → PDF
|
|
54
|
-
GET /health # Health check
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Use with `generate()` by setting `PDFN_HOST`:
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
PDFN_HOST=http://localhost:3456 node your-app.js
|
|
61
|
-
```
|
|
62
29
|
|
|
63
30
|
### `pdfn add`
|
|
64
31
|
|
|
65
|
-
Add
|
|
32
|
+
Add templates to your project:
|
|
66
33
|
|
|
67
34
|
```bash
|
|
68
35
|
npx pdfn add invoice # Add invoice template
|
|
69
36
|
npx pdfn add invoice --tailwind # With Tailwind classes
|
|
70
|
-
npx pdfn add --list #
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
| Template | Description |
|
|
74
|
-
|----------|-------------|
|
|
75
|
-
| `invoice` | Professional invoice with itemized billing |
|
|
76
|
-
| `letter` | US business correspondence |
|
|
77
|
-
| `contract` | Legal service agreement |
|
|
78
|
-
| `ticket` | Event admission ticket |
|
|
79
|
-
| `poster` | Event poster (landscape) |
|
|
80
|
-
| `report` | Sales report with charts (requires recharts) |
|
|
81
|
-
|
|
82
|
-
## PDF Generation
|
|
83
|
-
|
|
84
|
-
For PDF generation, choose based on your infrastructure:
|
|
85
|
-
|
|
86
|
-
**Option 1: Local dev server**
|
|
87
|
-
|
|
88
|
-
Use `pdfn dev` for development with `generate()`:
|
|
89
|
-
|
|
90
|
-
```tsx
|
|
91
|
-
import { generate } from '@pdfn/react';
|
|
92
|
-
|
|
93
|
-
// Set PDFN_HOST=http://localhost:3456
|
|
94
|
-
const pdf = await generate(<Invoice />);
|
|
37
|
+
npx pdfn add --list # List available templates
|
|
95
38
|
```
|
|
96
39
|
|
|
97
|
-
|
|
40
|
+
Templates: `invoice`, `letter`, `contract`, `ticket`, `poster`, `report`
|
|
98
41
|
|
|
99
|
-
|
|
42
|
+
## Usage
|
|
100
43
|
|
|
101
|
-
```
|
|
102
|
-
import {
|
|
103
|
-
import
|
|
44
|
+
```typescript
|
|
45
|
+
import { pdfn } from '@pdfn/react';
|
|
46
|
+
import Invoice from './pdfn-templates/invoice';
|
|
104
47
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const browser = await puppeteer.launch();
|
|
108
|
-
const page = await browser.newPage();
|
|
109
|
-
await page.setContent(html, { waitUntil: 'networkidle0' });
|
|
110
|
-
await page.waitForFunction(() => window.PDFN?.ready === true);
|
|
111
|
-
const pdf = await page.pdf({ preferCSSPageSize: true, printBackground: true });
|
|
112
|
-
await browser.close();
|
|
113
|
-
```
|
|
48
|
+
// Local dev (uses localhost:3456)
|
|
49
|
+
const client = pdfn();
|
|
114
50
|
|
|
115
|
-
|
|
51
|
+
// Or pdfn Cloud
|
|
52
|
+
// const client = pdfn(process.env.PDFN_API_KEY);
|
|
116
53
|
|
|
117
|
-
|
|
54
|
+
const { data, error } = await client.generate(<Invoice />);
|
|
118
55
|
|
|
119
|
-
|
|
56
|
+
if (error) {
|
|
57
|
+
console.error(error.message);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
120
60
|
|
|
121
|
-
|
|
122
|
-
import { generate } from '@pdfn/react';
|
|
123
|
-
|
|
124
|
-
// Set PDFN_API_KEY=pdfn_live_...
|
|
125
|
-
const pdf = await generate(<Invoice />);
|
|
61
|
+
// Use data.buffer
|
|
126
62
|
```
|
|
127
63
|
|
|
128
|
-
Get your API key at [console.pdfn.dev](https://console.pdfn.dev).
|
|
129
|
-
|
|
130
|
-
**All options produce identical PDFs** — same templates, same output.
|
|
131
|
-
|
|
132
64
|
## License
|
|
133
65
|
|
|
134
66
|
MIT
|