html2pdf_secure/
options.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct PdfOptions {
8 pub page_format: PageFormat,
10
11 pub orientation: PageOrientation,
13
14 pub margins: PageMargins,
16
17 pub print_background: bool,
19
20 pub scale: f64,
22
23 pub prefer_css_page_size: bool,
25
26 pub custom_width: Option<f64>,
28
29 pub custom_height: Option<f64>,
31
32 pub timeout_seconds: u64,
34
35 pub wait_for_network_idle: bool,
37
38 pub additional_wait_ms: u64,
40}
41
42impl Default for PdfOptions {
43 fn default() -> Self {
44 Self {
45 page_format: PageFormat::A4,
46 orientation: PageOrientation::Portrait,
47 margins: PageMargins::default(),
48 print_background: true,
49 scale: 1.0,
50 prefer_css_page_size: false,
51 custom_width: None,
52 custom_height: None,
53 timeout_seconds: 30,
54 wait_for_network_idle: true,
55 additional_wait_ms: 1000,
56 }
57 }
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62pub enum PageFormat {
63 A4,
64 A3,
65 A5,
66 Letter,
67 Legal,
68 Tabloid,
69 Ledger,
70}
71
72impl PageFormat {
73 pub fn dimensions(&self) -> (f64, f64) {
75 match self {
76 PageFormat::A4 => (8.27, 11.7),
77 PageFormat::A3 => (11.7, 16.5),
78 PageFormat::A5 => (5.8, 8.3),
79 PageFormat::Letter => (8.5, 11.0),
80 PageFormat::Legal => (8.5, 14.0),
81 PageFormat::Tabloid => (11.0, 17.0),
82 PageFormat::Ledger => (17.0, 11.0),
83 }
84 }
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
89pub enum PageOrientation {
90 Portrait,
91 Landscape,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
96pub struct PageMargins {
97 pub top: f64,
98 pub bottom: f64,
99 pub left: f64,
100 pub right: f64,
101}
102
103impl Default for PageMargins {
104 fn default() -> Self {
105 Self {
106 top: 1.0,
107 bottom: 1.0,
108 left: 1.0,
109 right: 1.0,
110 }
111 }
112}
113
114impl PageMargins {
115 pub fn uniform(margin: f64) -> Self {
117 Self {
118 top: margin,
119 bottom: margin,
120 left: margin,
121 right: margin,
122 }
123 }
124
125 pub fn symmetric(vertical: f64, horizontal: f64) -> Self {
127 Self {
128 top: vertical,
129 bottom: vertical,
130 left: horizontal,
131 right: horizontal,
132 }
133 }
134}