|
| 1 | +# SimplePDF Editor Automation |
| 2 | + |
| 3 | +Playwright-based CLI tool for programmatically creating and positioning fields in PDF documents using the SimplePDF editor. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Create TEXT, BOXED_TEXT, CHECKBOX, SIGNATURE, and PICTURE fields |
| 8 | +- Position fields using PDF standard coordinates (bottom-left origin) |
| 9 | +- Pre-fill field values including typed signatures |
| 10 | +- Browser opens for visual inspection after field creation |
| 11 | + |
| 12 | +## Quick Start |
| 13 | + |
| 14 | +```bash |
| 15 | +npm install |
| 16 | +npx tsx src/index.ts example.config.json |
| 17 | +``` |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +```bash |
| 22 | +npx tsx src/index.ts <config.json> [options] |
| 23 | + |
| 24 | +Options: |
| 25 | + --company-identifier Your SimplePDF company identifier (default: embed) |
| 26 | + --help Show help |
| 27 | +``` |
| 28 | + |
| 29 | +### Using Your Company Identifier |
| 30 | + |
| 31 | +```bash |
| 32 | +npx tsx src/index.ts config.json --company-identifier mycompany |
| 33 | +``` |
| 34 | + |
| 35 | +This connects to `https://mycompany.simplepdf.com`. |
| 36 | + |
| 37 | +## Configuration |
| 38 | + |
| 39 | +Create a JSON configuration file: |
| 40 | + |
| 41 | +```json |
| 42 | +{ |
| 43 | + "document": "https://example.com/document.pdf", |
| 44 | + "fields": [...] |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +### Document Source |
| 49 | + |
| 50 | +| Format | Example | |
| 51 | +|--------|---------| |
| 52 | +| URL | `"https://example.com/doc.pdf"` | |
| 53 | +| Local file | `"./documents/form.pdf"` | |
| 54 | + |
| 55 | +## Field Types |
| 56 | + |
| 57 | +### TEXT |
| 58 | + |
| 59 | +Single-line text input. |
| 60 | + |
| 61 | +```json |
| 62 | +{ |
| 63 | + "type": "TEXT", |
| 64 | + "x": 100, |
| 65 | + "y": 700, |
| 66 | + "width": 200, |
| 67 | + "height": 20, |
| 68 | + "page": 1, |
| 69 | + "value": "John Doe" |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +### BOXED_TEXT |
| 74 | + |
| 75 | +Multi-line text with border. |
| 76 | + |
| 77 | +```json |
| 78 | +{ |
| 79 | + "type": "BOXED_TEXT", |
| 80 | + "x": 100, |
| 81 | + "y": 600, |
| 82 | + "width": 300, |
| 83 | + "height": 100, |
| 84 | + "page": 1, |
| 85 | + "value": "Additional notes here..." |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +### CHECKBOX |
| 90 | + |
| 91 | +Checkable box. Must be square (equal width/height). |
| 92 | + |
| 93 | +```json |
| 94 | +{ |
| 95 | + "type": "CHECKBOX", |
| 96 | + "x": 100, |
| 97 | + "y": 550, |
| 98 | + "width": 12, |
| 99 | + "height": 12, |
| 100 | + "page": 1, |
| 101 | + "value": true |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +### SIGNATURE |
| 106 | + |
| 107 | +Signature field with multiple value formats. |
| 108 | + |
| 109 | +```json |
| 110 | +{ |
| 111 | + "type": "SIGNATURE", |
| 112 | + "x": 100, |
| 113 | + "y": 450, |
| 114 | + "width": 200, |
| 115 | + "height": 60, |
| 116 | + "page": 1, |
| 117 | + "value": "John Doe" |
| 118 | +} |
| 119 | +``` |
| 120 | + |
| 121 | +**Value formats:** |
| 122 | + |
| 123 | +| Format | Example | Result | |
| 124 | +|--------|---------|--------| |
| 125 | +| Plain text | `"John Doe"` | Typed signature (cursive font) | |
| 126 | +| URL | `"https://example.com/sig.png"` | Drawn signature from image | |
| 127 | +| Data URL | `"data:image/png;base64,..."` | Drawn signature from base64 | |
| 128 | +| Local file | `"./signatures/john.png"` | Drawn signature from file | |
| 129 | + |
| 130 | +### PICTURE |
| 131 | + |
| 132 | +Image field. |
| 133 | + |
| 134 | +```json |
| 135 | +{ |
| 136 | + "type": "PICTURE", |
| 137 | + "x": 100, |
| 138 | + "y": 300, |
| 139 | + "width": 150, |
| 140 | + "height": 150, |
| 141 | + "page": 1, |
| 142 | + "value": "https://example.com/photo.jpg" |
| 143 | +} |
| 144 | +``` |
| 145 | + |
| 146 | +**Value formats:** URL, data URL, or local file path. |
| 147 | + |
| 148 | +## Coordinate System |
| 149 | + |
| 150 | +Uses PDF standard coordinates: |
| 151 | + |
| 152 | +``` |
| 153 | +┌─────────────────────────────┐ |
| 154 | +│ │ ↑ |
| 155 | +│ │ │ |
| 156 | +│ PDF Page │ │ Y increases |
| 157 | +│ │ │ |
| 158 | +│ │ │ |
| 159 | +└─────────────────────────────┘ |
| 160 | +(0,0) ───────────────────────→ |
| 161 | + X increases |
| 162 | +``` |
| 163 | + |
| 164 | +- **Origin**: Bottom-left corner of page |
| 165 | +- **Units**: Points (1/72 inch) |
| 166 | +- **Y-axis**: Increases upward |
| 167 | + |
| 168 | +## Examples |
| 169 | + |
| 170 | +### Basic Form Fill |
| 171 | + |
| 172 | +```json |
| 173 | +{ |
| 174 | + "document": "https://cdn.simplepdf.com/simple-pdf/assets/sample.pdf", |
| 175 | + "fields": [ |
| 176 | + { |
| 177 | + "type": "TEXT", |
| 178 | + "x": 72, |
| 179 | + "y": 700, |
| 180 | + "width": 200, |
| 181 | + "height": 14, |
| 182 | + "page": 1, |
| 183 | + "value": "John" |
| 184 | + }, |
| 185 | + { |
| 186 | + "type": "TEXT", |
| 187 | + "x": 320, |
| 188 | + "y": 700, |
| 189 | + "width": 200, |
| 190 | + "height": 14, |
| 191 | + "page": 1, |
| 192 | + "value": "Doe" |
| 193 | + }, |
| 194 | + { |
| 195 | + "type": "SIGNATURE", |
| 196 | + "x": 72, |
| 197 | + "y": 100, |
| 198 | + "width": 200, |
| 199 | + "height": 60, |
| 200 | + "page": 1, |
| 201 | + "value": "John Doe" |
| 202 | + } |
| 203 | + ] |
| 204 | +} |
| 205 | +``` |
| 206 | + |
| 207 | +### Multi-Page Document |
| 208 | + |
| 209 | +```json |
| 210 | +{ |
| 211 | + "document": "./documents/multi-page.pdf", |
| 212 | + "fields": [ |
| 213 | + { |
| 214 | + "type": "TEXT", |
| 215 | + "x": 72, |
| 216 | + "y": 700, |
| 217 | + "width": 200, |
| 218 | + "height": 14, |
| 219 | + "page": 1, |
| 220 | + "value": "Page 1 content" |
| 221 | + }, |
| 222 | + { |
| 223 | + "type": "TEXT", |
| 224 | + "x": 72, |
| 225 | + "y": 700, |
| 226 | + "width": 200, |
| 227 | + "height": 14, |
| 228 | + "page": 2, |
| 229 | + "value": "Page 2 content" |
| 230 | + }, |
| 231 | + { |
| 232 | + "type": "SIGNATURE", |
| 233 | + "x": 72, |
| 234 | + "y": 100, |
| 235 | + "width": 200, |
| 236 | + "height": 60, |
| 237 | + "page": 3, |
| 238 | + "value": "Final Signature" |
| 239 | + } |
| 240 | + ] |
| 241 | +} |
| 242 | +``` |
| 243 | + |
| 244 | +## How It Works |
| 245 | + |
| 246 | +The tool uses the SimplePDF editor's iframe postMessage API: |
| 247 | + |
| 248 | +1. Embeds the editor in an iframe |
| 249 | +2. Waits for `DOCUMENT_LOADED` event |
| 250 | +3. Sends `CLEAR_FIELDS` to remove existing fields |
| 251 | +4. Sends `CREATE_FIELD` for each configured field |
| 252 | +5. Leaves browser open for inspection |
| 253 | + |
| 254 | +## Requirements |
| 255 | + |
| 256 | +- Playwright (installed automatically via npm) |
| 257 | + |
| 258 | +## License |
| 259 | + |
| 260 | +MIT |
0 commit comments