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 CHANGED
@@ -1,14 +1,6 @@
1
1
  # pdfn
2
2
 
3
- CLI and PDF server for pdfn. Dev server with live preview, production server for PDF generation.
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. Intended for local development and template iteration only.
15
+ Development server with live preview and hot reload.
24
16
 
25
17
  ```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
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
- | `--open` | `false` | Open browser automatically |
35
-
36
- Templates are loaded from `./pdfn-templates` by convention.
25
+ | `--templates` | `./pdfn-templates` | Templates directory |
26
+ | `--open` | `false` | Open browser on start |
27
+ | `--no-open` | - | Don't open browser |
37
28
 
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
- ### `pdfn serve`
29
+ ### `pdfn add`
45
30
 
46
- Production server (headless, no UI). Intended for production use behind an API or worker.
31
+ Add starter templates to your project.
47
32
 
48
33
  ```bash
49
- npx pdfn serve # Start server
50
- npx pdfn serve --port 3456 # Custom port
51
- npx pdfn serve --max-concurrent 10 # Concurrency limit
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
- | Option | Env Variable | Default | Description |
55
- |--------|--------------|---------|-------------|
56
- | `--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 |
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
- ### `pdfn add`
48
+ ## Production PDFs
61
49
 
62
- Add starter templates to your project.
50
+ For production PDF generation, choose based on your infrastructure:
63
51
 
64
- ```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
71
- npx pdfn add --list # Show all templates
72
- ```
52
+ **Option 1: Self-host with Puppeteer/Playwright**
73
53
 
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 |
54
+ Use `render()` to get print-ready HTML, then convert with your own browser:
79
55
 
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 |
56
+ ```tsx
57
+ import { render } from '@pdfn/react';
58
+ import puppeteer from 'puppeteer';
87
59
 
88
- ## Server API
60
+ const html = await render(<Invoice />);
89
61
 
90
- ```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)
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
- ## Embedding in Your Server
70
+ Works with Puppeteer, Playwright, Browserless, @sparticuz/chromium, or any Chromium setup.
71
+
72
+ **Option 2: pdfn Cloud**
104
73
 
105
- ```ts
106
- import { createServer } from 'pdfn/server';
74
+ Let pdfn manage the browser infrastructure:
107
75
 
108
- const server = createServer({
109
- port: 3456,
110
- maxConcurrent: 10,
111
- timeout: 30000
112
- });
76
+ ```tsx
77
+ import { generate } from '@pdfn/react';
113
78
 
114
- await server.start();
79
+ // Set PDFN_API_KEY environment variable
80
+ const pdf = await generate(<Invoice />);
115
81
  ```
116
82
 
117
- ## Environment Variables
83
+ Get your API key at [console.pdfn.dev](https://console.pdfn.dev).
118
84
 
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 |
85
+ **Both produce identical PDFs** same templates, same output.
125
86
 
126
87
  ## License
127
88