pdfn 0.0.1 → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 PDFN
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
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # pdfn
2
+
3
+ CLI and PDF server for pdfn. Dev server with live preview, production server for PDF generation.
4
+
5
+ > Requires headless Chromium (Puppeteer/Playwright compatible). For serverless, use [@sparticuz/chromium](https://github.com/Sparticuz/chromium) or a hosted browser service.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install -D pdfn
11
+ ```
12
+
13
+ ## Commands
14
+
15
+ ### `pdfn dev`
16
+
17
+ Development server with live preview and hot reload. Intended for local development and template iteration only.
18
+
19
+ ```bash
20
+ npx pdfn dev # Start on port 3456
21
+ npx pdfn dev --open # Start and open browser
22
+ npx pdfn dev --port 4000 # Custom port
23
+ npx pdfn dev --templates ./src # Custom templates directory
24
+ ```
25
+
26
+ | Option | Default | Description |
27
+ |--------|---------|-------------|
28
+ | `--port` | `3456` | Server port |
29
+ | `--templates` | `./pdf-templates` | Templates directory |
30
+ | `--open` | `false` | Open browser automatically |
31
+
32
+ Features:
33
+ - Auto-discovers templates in your templates directory
34
+ - Live preview UI with hot reload
35
+ - Performance metrics and debug overlays
36
+ - Exposes a local `/generate` endpoint for PDF generation
37
+
38
+ ### `pdfn serve`
39
+
40
+ Production server (headless, no UI). Intended for production use behind an API or worker.
41
+
42
+ ```bash
43
+ npx pdfn serve # Start server
44
+ npx pdfn serve --port 3456 # Custom port
45
+ npx pdfn serve --max-concurrent 10 # Concurrency limit
46
+ ```
47
+
48
+ | Option | Env Variable | Default | Description |
49
+ |--------|--------------|---------|-------------|
50
+ | `--port` | `PDFN_PORT` | `3456` | Server port |
51
+ | `--max-concurrent` | `PDFN_MAX_CONCURRENT` | `5` | Max concurrent PDF generations |
52
+ | `--timeout` | `PDFN_TIMEOUT` | `30000` | Request timeout in ms |
53
+
54
+ ### `pdfn add`
55
+
56
+ Add starter templates to your project.
57
+
58
+ ```bash
59
+ npx pdfn add invoice # Add invoice template (inline styles)
60
+ npx pdfn add invoice --tailwind # Add with Tailwind classes
61
+ npx pdfn add letter # Add business letter
62
+ npx pdfn add contract # Add contract template
63
+ npx pdfn add ticket # Add event ticket
64
+ npx pdfn add poster # Add poster template
65
+ npx pdfn add --list # Show all templates
66
+ npx pdfn add invoice --output ./src/templates
67
+ ```
68
+
69
+ | Option | Default | Description |
70
+ |--------|---------|-------------|
71
+ | `--inline` | ✓ | Use inline styles (default, no extra dependencies) |
72
+ | `--tailwind` | | Use Tailwind CSS classes (requires `@pdfn/tailwind`) |
73
+ | `--output` | `./pdf-templates` | Output directory |
74
+ | `--force` | | Overwrite existing files |
75
+
76
+ | Template | Description | Page Size |
77
+ |----------|-------------|-----------|
78
+ | `invoice` | Professional invoice with itemized billing | A4 |
79
+ | `letter` | US business correspondence | Letter |
80
+ | `contract` | Legal service agreement | Legal |
81
+ | `ticket` | Event admission ticket | A5 |
82
+ | `poster` | Event poster (landscape) | Tabloid |
83
+
84
+ ## Server API
85
+
86
+ ```bash
87
+ # Generate PDF from HTML
88
+ POST /generate
89
+ Content-Type: application/json
90
+ { "html": "<html>...</html>" }
91
+ # HTML must be print-ready and fully self-contained (fonts/images embedded)
92
+ # Returns: application/pdf
93
+
94
+ # Health check
95
+ GET /health
96
+ # Returns: { "status": "ok", "browser": "connected", ... }
97
+ ```
98
+
99
+ ## Embedding in Your Server
100
+
101
+ ```ts
102
+ import { createServer } from 'pdfn/server';
103
+
104
+ const server = createServer({
105
+ port: 3456,
106
+ maxConcurrent: 10,
107
+ timeout: 30000
108
+ });
109
+
110
+ await server.start();
111
+ ```
112
+
113
+ ## Environment Variables
114
+
115
+ | Variable | Default | Description |
116
+ |----------|---------|-------------|
117
+ | `PDFN_PORT` | `3456` | Server port |
118
+ | `PDFN_MAX_CONCURRENT` | `5` | Max concurrent PDF generations |
119
+ | `PDFN_TIMEOUT` | `30000` | Request timeout in ms |
120
+ | `DEBUG` | - | Set to `pdfn:cli` or `pdfn:*` to enable logging |
121
+
122
+ ## License
123
+
124
+ MIT