printwell-cli 0.1.11

Command-line tool for HTML to PDF conversion
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
//! CLI argument structures.

use clap::{Args, Parser};

/// Layout flags for PDF conversion
#[derive(Args)]
pub struct ConvertLayoutFlags {
    /// Use landscape orientation
    #[arg(long)]
    pub landscape: bool,

    /// Don't print background graphics
    #[arg(long)]
    pub no_background: bool,
}

/// Behavior flags for PDF conversion
#[derive(Args)]
pub struct ConvertBehaviorFlags {
    /// Detect HTML form elements and output their positions
    #[arg(long)]
    pub detect_forms: bool,

    /// Auto-convert detected HTML forms to native PDF form fields
    #[arg(long)]
    pub convert_forms: bool,
}

#[derive(Parser)]
pub struct ConvertArgs {
    /// Input HTML file, URL, or '-' for stdin
    pub input: String,

    /// Output PDF file (default: stdout or derived from input)
    #[arg(short, long)]
    pub output: Option<String>,

    /// Page size (A3, A4, A5, Letter, Legal, Tabloid)
    #[arg(long, default_value = "A4")]
    pub page_size: String,

    /// Custom page width (e.g., "210mm")
    #[arg(long)]
    pub width: Option<String>,

    /// Custom page height (e.g., "297mm")
    #[arg(long)]
    pub height: Option<String>,

    /// Page margins (e.g., "10mm" or "10mm,20mm,10mm,20mm")
    #[arg(long, default_value = "10mm")]
    pub margin: String,

    /// Layout options
    #[command(flatten)]
    pub layout: ConvertLayoutFlags,

    /// Scale factor
    #[arg(long, default_value = "1.0")]
    pub scale: f64,

    /// Page ranges (e.g., "1-5,8")
    #[arg(long)]
    pub page_ranges: Option<String>,

    /// Header HTML template
    #[arg(long)]
    pub header: Option<String>,

    /// Footer HTML template
    #[arg(long)]
    pub footer: Option<String>,

    /// Behavior options
    #[command(flatten)]
    pub behavior: ConvertBehaviorFlags,

    /// Navigation/script timeout (e.g., "30s")
    #[arg(long, default_value = "30s")]
    pub timeout: String,

    /// CSS selectors for boundary extraction (comma-separated)
    #[arg(long)]
    pub boundaries: Option<String>,

    /// Output boundaries to JSON file
    #[arg(long)]
    pub boundaries_output: Option<String>,

    /// Output detected form elements to JSON file
    #[arg(long)]
    pub forms_output: Option<String>,

    /// Validate detected forms against rules JSON file
    #[arg(long)]
    pub validate_forms: Option<String>,

    /// Output validation results to JSON file
    #[arg(long)]
    pub validation_output: Option<String>,

    /// Custom font files to load (format: "family:path" e.g., "MyFont:./font.ttf")
    #[arg(long)]
    pub font: Vec<String>,

    // PDF Metadata options
    /// PDF document title
    #[arg(long)]
    pub title: Option<String>,

    /// PDF document author
    #[arg(long)]
    pub author: Option<String>,

    /// PDF document subject
    #[arg(long)]
    pub subject: Option<String>,

    /// PDF document keywords (comma-separated)
    #[arg(long)]
    pub keywords: Option<String>,

    /// PDF creator application name (default: printwell)
    #[arg(long)]
    pub creator: Option<String>,

    /// PDF producer name (default: printwell)
    #[arg(long)]
    pub producer: Option<String>,
}

#[cfg(feature = "forms")]
#[derive(Parser)]
pub struct FormsArgs {
    /// Input PDF file
    pub input: String,

    /// Output PDF file
    #[arg(short, long)]
    pub output: String,

    /// Add text field (format: "name:page:x,y,w,h")
    #[arg(long)]
    pub text_field: Vec<String>,

    /// Add checkbox (format: "name:page:x,y,size")
    #[arg(long)]
    pub checkbox: Vec<String>,

    /// Add dropdown (format: "name:page:x,y,w,h:opt1,opt2,...")
    #[arg(long)]
    pub dropdown: Vec<String>,

    /// Add signature field (format: "name:page:x,y,w,h")
    #[arg(long)]
    pub signature_field: Vec<String>,
}

#[cfg(feature = "signing")]
#[derive(Parser)]
pub struct SignArgs {
    /// Input PDF file
    pub input: String,

    /// Output PDF file
    #[arg(short, long)]
    pub output: String,

    /// PKCS#12 certificate file (.p12/.pfx)
    #[arg(long)]
    pub certificate: String,

    /// Certificate password (WARNING: visible in process listings, prefer --password-file)
    #[arg(long)]
    pub password: Option<String>,

    /// Read certificate password from file (more secure than --password)
    #[arg(long)]
    pub password_file: Option<String>,

    /// Read certificate password from environment variable (more secure than --password)
    #[arg(long)]
    pub password_env: Option<String>,

    /// Reason for signing
    #[arg(long)]
    pub reason: Option<String>,

    /// Location of signing
    #[arg(long)]
    pub location: Option<String>,

    /// Signature level (B, T, LT, LTA)
    #[arg(long, default_value = "B")]
    pub level: String,

    /// Timestamp server URL
    #[arg(long)]
    pub timestamp_url: Option<String>,

    /// Visible signature field name
    #[arg(long)]
    pub visible: Option<String>,

    /// Visible signature position (format: "page:x,y,w,h")
    #[arg(long)]
    pub position: Option<String>,

    /// Create a certification signature (certifies the document)
    #[arg(long)]
    pub certify: bool,

    /// MDP permissions for certification (1=no-changes, 2=form-filling, 3=annotations)
    #[arg(long, default_value = "2")]
    pub mdp: String,
}

#[cfg(feature = "signing")]
#[derive(Parser)]
pub struct VerifyArgs {
    /// Input PDF file
    pub input: String,

    /// Output format (text, json)
    #[arg(long, default_value = "text")]
    pub format: String,

    /// Use system trust store for certificate chain validation
    #[arg(long)]
    pub use_system_trust: bool,
}

#[cfg(feature = "signing")]
#[derive(Parser)]
pub struct ListFieldsArgs {
    /// Input PDF file
    pub input: String,

    /// Output format (text, json)
    #[arg(long, default_value = "text")]
    pub format: String,
}

/// Print permission flags for encryption
#[cfg(feature = "encrypt")]
#[derive(Args)]
pub struct PrintPermissionFlags {
    /// Allow printing
    #[arg(long)]
    pub allow_print: bool,

    /// Allow high-quality printing
    #[arg(long)]
    pub allow_print_hq: bool,
}

/// Content permission flags for encryption
#[cfg(feature = "encrypt")]
#[derive(Args)]
pub struct ContentPermissionFlags {
    /// Allow copying text and graphics
    #[arg(long)]
    pub allow_copy: bool,

    /// Allow extracting text for accessibility
    #[arg(long)]
    pub allow_accessibility: bool,
}

/// Edit permission flags for encryption
#[cfg(feature = "encrypt")]
#[derive(Args)]
pub struct EditPermissionFlags {
    /// Allow modifying the document
    #[arg(long)]
    pub allow_modify: bool,

    /// Allow adding annotations
    #[arg(long)]
    pub allow_annotate: bool,

    /// Allow assembling the document
    #[arg(long)]
    pub allow_assemble: bool,
}

/// Form and special permission flags for encryption
#[cfg(feature = "encrypt")]
#[derive(Args)]
pub struct FormPermissionFlags {
    /// Allow filling form fields
    #[arg(long)]
    pub allow_fill_forms: bool,

    /// Allow all permissions
    #[arg(long)]
    pub allow_all: bool,
}

#[cfg(feature = "encrypt")]
#[derive(Parser)]
pub struct EncryptArgs {
    /// Input PDF file
    pub input: String,

    /// Output PDF file
    #[arg(short, long)]
    pub output: String,

    /// Owner password (WARNING: visible in process listings, prefer --owner-password-file)
    #[arg(long)]
    pub owner_password: Option<String>,

    /// Read owner password from file (more secure than --owner-password)
    #[arg(long)]
    pub owner_password_file: Option<String>,

    /// Read owner password from environment variable (more secure than --owner-password)
    #[arg(long)]
    pub owner_password_env: Option<String>,

    /// User password (WARNING: visible in process listings, prefer --user-password-file)
    #[arg(long)]
    pub user_password: Option<String>,

    /// Read user password from file (more secure than --user-password)
    #[arg(long)]
    pub user_password_file: Option<String>,

    /// Read user password from environment variable (more secure than --user-password)
    #[arg(long)]
    pub user_password_env: Option<String>,

    /// Print permissions
    #[command(flatten)]
    pub print_perms: PrintPermissionFlags,

    /// Content permissions
    #[command(flatten)]
    pub content_perms: ContentPermissionFlags,

    /// Edit permissions
    #[command(flatten)]
    pub edit_perms: EditPermissionFlags,

    /// Form permissions
    #[command(flatten)]
    pub form_perms: FormPermissionFlags,

    /// Encryption algorithm (aes256, aes128, rc4)
    #[arg(long, default_value = "aes256")]
    pub algorithm: String,
}

#[cfg(feature = "encrypt")]
#[derive(Parser)]
pub struct DecryptArgs {
    /// Input encrypted PDF file
    pub input: String,

    /// Output PDF file (decrypted)
    #[arg(short, long)]
    pub output: String,

    /// Password to decrypt the PDF (WARNING: visible in process listings, prefer --password-file)
    #[arg(long)]
    pub password: Option<String>,

    /// Read password from file (more secure than --password)
    #[arg(long)]
    pub password_file: Option<String>,

    /// Read password from environment variable (more secure than --password)
    #[arg(long)]
    pub password_env: Option<String>,
}

#[cfg(feature = "watermark")]
#[derive(Parser)]
pub struct WatermarkArgs {
    /// Input PDF file
    pub input: String,

    /// Output PDF file
    #[arg(short, long)]
    pub output: String,

    /// Watermark text
    #[arg(long)]
    pub text: Option<String>,

    /// Watermark image file (PNG or JPEG)
    #[arg(long)]
    pub image: Option<String>,

    /// Position: center, top-left, top-center, top-right, middle-left, middle-right,
    /// bottom-left, bottom-center, bottom-right, or "x,y" for custom position
    #[arg(long, default_value = "center")]
    pub position: String,

    /// Rotation in degrees (counter-clockwise)
    #[arg(long, default_value = "0")]
    pub rotation: f32,

    /// Opacity (0.0 = transparent, 1.0 = opaque)
    #[arg(long, default_value = "0.3")]
    pub opacity: f32,

    /// Font size for text watermarks
    #[arg(long, default_value = "72")]
    pub font_size: f32,

    /// Color as hex (e.g., "#FF0000" or "gray")
    #[arg(long, default_value = "gray")]
    pub color: String,

    /// Place watermark in foreground (default: background)
    #[arg(long)]
    pub foreground: bool,

    /// Pages to watermark (e.g., "1,3,5" or "1-10" or "odd" or "even" or "first" or "last")
    #[arg(long)]
    pub pages: Option<String>,

    /// Scale factor for the watermark
    #[arg(long, default_value = "1.0")]
    pub scale: f32,
}

#[cfg(feature = "bookmarks")]
#[derive(Parser)]
pub struct BookmarksArgs {
    /// Input PDF file
    pub input: String,

    /// Output PDF file (for adding bookmarks)
    #[arg(short, long)]
    pub output: Option<String>,

    /// Add bookmark (format: "title:page" or "`title:page:y_position`" or "`title:page:y_position:parent_index`")
    #[arg(long)]
    pub add: Vec<String>,

    /// Extract bookmarks to JSON file
    #[arg(long)]
    pub extract: Option<String>,

    /// Bookmarks JSON file to add (alternative to --add)
    #[arg(long)]
    pub from_json: Option<String>,

    /// Output format for extraction (text, json)
    #[arg(long, default_value = "text")]
    pub format: String,
}

#[cfg(feature = "annotations")]
#[derive(Parser)]
pub struct AnnotateArgs {
    /// Input PDF file
    pub input: String,

    /// Output PDF file (for adding/removing annotations)
    #[arg(short, long)]
    pub output: Option<String>,

    /// Add highlight annotation (format: "page:x:y:width:height" or "page:x:y:width:height:color")
    #[arg(long)]
    pub highlight: Vec<String>,

    /// Add text note annotation (format: "page:x:y:contents")
    #[arg(long)]
    pub note: Vec<String>,

    /// Add underline annotation (format: "page:x:y:width:height")
    #[arg(long)]
    pub underline: Vec<String>,

    /// Add strikeout annotation (format: "page:x:y:width:height")
    #[arg(long)]
    pub strikeout: Vec<String>,

    /// Add square/rectangle annotation (format: "page:x:y:width:height:color")
    #[arg(long)]
    pub square: Vec<String>,

    /// List existing annotations
    #[arg(long)]
    pub list: bool,

    /// Remove all annotations (or specific types)
    #[arg(long)]
    pub remove: bool,

    /// Page to filter for remove operation (1-indexed)
    #[arg(long)]
    pub page: Option<u32>,

    /// Annotation color (hex, e.g., "#FF0000" for red)
    #[arg(long, default_value = "#FFFF00")]
    pub color: String,

    /// Output format for list (text, json)
    #[arg(long, default_value = "text")]
    pub format: String,
}

#[cfg(feature = "pdfa")]
#[derive(Parser)]
pub struct PdfaValidateArgs {
    /// Input PDF file
    pub input: String,

    /// PDF/A level to validate against (1b, 1a, 2b, 2u, 2a, 3b, 3u, 3a)
    #[arg(long, default_value = "2b")]
    pub level: String,

    /// Output format (text, json)
    #[arg(long, default_value = "text")]
    pub format: String,
}

#[cfg(feature = "pdfa")]
#[derive(Parser)]
pub struct PdfaConvertArgs {
    /// Input PDF file
    pub input: String,

    /// Output PDF file
    #[arg(short, long)]
    pub output: String,

    /// PDF/A level (1b, 1a, 2b, 2u, 2a, 3b, 3u, 3a)
    #[arg(long, default_value = "2b")]
    pub level: String,

    /// Document title
    #[arg(long)]
    pub title: Option<String>,

    /// Document author
    #[arg(long)]
    pub author: Option<String>,
}

#[cfg(feature = "pdfua")]
#[derive(Parser)]
pub struct PdfuaValidateArgs {
    /// Input PDF file
    pub input: String,

    /// PDF/UA level to validate against (1, 2)
    #[arg(long, default_value = "1")]
    pub level: String,

    /// Output format (text, json)
    #[arg(long, default_value = "text")]
    pub format: String,
}

#[cfg(feature = "pdfua")]
#[derive(Parser)]
pub struct PdfuaConvertArgs {
    /// Input PDF file
    pub input: String,

    /// Output PDF file
    #[arg(short, long)]
    pub output: String,

    /// PDF/UA level (1, 2)
    #[arg(long, default_value = "1")]
    pub level: String,

    /// Document title
    #[arg(long)]
    pub title: Option<String>,

    /// Document language (BCP 47 format, e.g., "en-US")
    #[arg(long, default_value = "en")]
    pub language: String,
}

#[derive(Parser)]
pub struct ConvertBatchArgs {
    /// Input HTML files (multiple allowed)
    #[arg(required = true)]
    pub inputs: Vec<String>,

    /// Output directory for generated PDFs
    #[arg(short, long, default_value = ".")]
    pub output_dir: String,

    /// Maximum concurrent conversions
    #[arg(long, default_value = "4")]
    pub workers: usize,

    /// Page size (A3, A4, A5, Letter, Legal, Tabloid)
    #[arg(long, default_value = "A4")]
    pub page_size: String,

    /// Print background colors and images
    #[arg(long)]
    pub background: bool,

    /// Use landscape orientation
    #[arg(long)]
    pub landscape: bool,
}

#[derive(Parser)]
pub struct InfoArgs {
    /// Show renderer information
    #[arg(long)]
    pub renderer: bool,

    /// PDF file to inspect
    pub input: Option<String>,
}