pdfn 0.4.6 → 0.5.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 CHANGED
@@ -1,14 +1,8 @@
1
1
  # pdfn
2
2
 
3
- CLI and PDF server for pdfn. Dev server with live preview, production server for PDF generation.
3
+ CLI for pdfn. Dev server with live preview, production server for PDF generation.
4
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`
5
+ > For serverless deployments, use [@sparticuz/chromium](https://github.com/Sparticuz/chromium) or a hosted browser service.
12
6
 
13
7
  ## Installation
14
8
 
@@ -20,108 +14,76 @@ npm install -D pdfn
20
14
 
21
15
  ### `pdfn dev`
22
16
 
23
- Development server with live preview and hot reload. Intended for local development and template iteration only.
17
+ Development server with live preview and hot reload.
24
18
 
25
19
  ```bash
26
- npx pdfn dev # Start on port 3456
27
- npx pdfn dev --open # Start and open browser
28
- npx pdfn dev --port 4000 # Custom port
20
+ npx pdfn dev # Start on port 3456
21
+ npx pdfn dev --open # Start and open browser
29
22
  ```
30
23
 
31
- | Option | Default | Description |
32
- |--------|---------|-------------|
33
- | `--port` | `3456` | Server port |
34
- | `--open` | `false` | Open browser automatically |
35
-
36
- Templates are loaded from `./pdfn-templates` by convention.
37
-
38
- Features:
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
24
  ### `pdfn serve`
45
25
 
46
- Production server (headless, no UI). Intended for production use behind an API or worker.
26
+ Production server for PDF generation. Requires Docker (uses [Gotenberg](https://gotenberg.dev)).
47
27
 
48
28
  ```bash
49
- npx pdfn serve # Start server
50
- npx pdfn serve --port 3456 # Custom port
51
- npx pdfn serve --max-concurrent 10 # Concurrency limit
29
+ npx pdfn serve # Start server on port 3456
30
+ npx pdfn serve --port 8080 # Custom port
52
31
  ```
53
32
 
54
33
  | Option | Env Variable | Default | Description |
55
34
  |--------|--------------|---------|-------------|
56
35
  | `--port` | `PDFN_PORT` | `3456` | Server port |
57
- | `--max-concurrent` | `PDFN_MAX_CONCURRENT` | `5` | Max concurrent PDF generations |
58
- | `--timeout` | `PDFN_TIMEOUT` | `30000` | Request timeout in ms |
36
+ | `--mode` | - | `production` | Environment mode (loads .env.[mode]) |
37
+
38
+ Docker runs Gotenberg which handles PDF rendering with Chromium.
59
39
 
60
40
  ### `pdfn add`
61
41
 
62
42
  Add starter templates to your project.
63
43
 
64
44
  ```bash
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
45
+ npx pdfn add invoice # Add invoice template
46
+ npx pdfn add invoice --tailwind # With Tailwind classes
71
47
  npx pdfn add --list # Show all templates
72
48
  ```
73
49
 
74
- | Option | Default | Description |
75
- |--------|---------|-------------|
76
- | `--inline` | | Use inline styles (default, no extra dependencies) |
77
- | `--tailwind` | | Use Tailwind CSS classes (requires `@pdfn/tailwind`) |
78
- | `--force` | | Overwrite existing files |
79
-
80
- | Template | Description | Page Size |
81
- |----------|-------------|-----------|
82
- | `invoice` | Professional invoice with itemized billing | A4 |
83
- | `letter` | US business correspondence | Letter |
84
- | `contract` | Legal service agreement | Legal |
85
- | `ticket` | Event admission ticket | A5 |
86
- | `poster` | Event poster (landscape) | Tabloid |
50
+ | Template | Description |
51
+ |----------|-------------|
52
+ | `invoice` | Professional invoice with itemized billing |
53
+ | `letter` | US business correspondence |
54
+ | `contract` | Legal service agreement |
55
+ | `ticket` | Event admission ticket |
56
+ | `poster` | Event poster (landscape) |
57
+ | `report` | Sales report with charts (requires recharts) |
87
58
 
88
59
  ## Server API
89
60
 
61
+ Both `pdfn dev` and `pdfn serve` expose a Gotenberg-compatible API:
62
+
90
63
  ```bash
91
- # Generate PDF from HTML
92
- POST /generate
93
- Content-Type: application/json
94
- { "html": "<html>...</html>" }
95
- # HTML must be print-ready and fully self-contained (fonts/images embedded)
64
+ POST /forms/chromium/convert/html
65
+ Content-Type: multipart/form-data
66
+ # Form fields: files (index.html), waitForExpression, preferCssPageSize, printBackground
96
67
  # Returns: application/pdf
97
68
 
98
- # Health check
99
69
  GET /health
100
- # Returns: { "status": "ok", "browser": "connected", ... }
70
+ # Returns: { "status": "ok", ... }
101
71
  ```
102
72
 
73
+ The `generate()` function from `@pdfn/react` handles this API automatically.
74
+
103
75
  ## Embedding in Your Server
104
76
 
77
+ For embedding a PDF server in your Node.js application (without Docker):
78
+
105
79
  ```ts
106
80
  import { createServer } from 'pdfn/server';
107
81
 
108
- const server = createServer({
109
- port: 3456,
110
- maxConcurrent: 10,
111
- timeout: 30000
112
- });
113
-
82
+ const server = createServer({ port: 3456, maxConcurrent: 10 });
114
83
  await server.start();
115
84
  ```
116
85
 
117
- ## Environment Variables
118
-
119
- | Variable | Default | Description |
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 |
86
+ This uses embedded Puppeteer and exposes both the legacy `/generate` endpoint and the Gotenberg-compatible `/forms/chromium/convert/html` endpoint.
125
87
 
126
88
  ## License
127
89