1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Deserialize)]
4pub struct PdfRect {
5 pub x: f64,
6 pub y: f64,
7 pub width: f64,
8 pub height: f64,
9}
10
11#[derive(Debug, Clone, Copy, PartialEq, Deserialize)]
12pub struct PdfPoint {
13 pub x: f64,
14 pub y: f64,
15}
16
17#[derive(Debug, Clone, Copy, PartialEq, Deserialize)]
18pub struct PdfSize {
19 pub width: f64,
20 pub height: f64,
21}
22
23#[derive(Debug, Clone, Copy, PartialEq, Deserialize)]
24pub struct PdfEdgeInsets {
25 pub top: f64,
26 pub left: f64,
27 pub bottom: f64,
28 pub right: f64,
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Deserialize)]
32pub struct PdfColor {
33 pub red: f64,
34 pub green: f64,
35 pub blue: f64,
36 pub alpha: f64,
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
40pub struct PdfTextRange {
41 pub location: usize,
42 pub length: usize,
43}
44
45#[derive(Debug, Clone, Copy, PartialEq, Eq)]
46#[repr(i32)]
47pub enum DisplayBox {
48 MediaBox = 0,
49 CropBox = 1,
50 BleedBox = 2,
51 TrimBox = 3,
52 ArtBox = 4,
53}
54
55impl DisplayBox {
56 #[must_use]
57 pub const fn as_raw(self) -> i32 {
58 self as i32
59 }
60}
61
62#[derive(Debug, Clone, Copy, PartialEq, Eq)]
63#[repr(i32)]
64pub enum PdfBorderStyle {
65 Solid = 0,
66 Dashed = 1,
67 Beveled = 2,
68 Inset = 3,
69 Underline = 4,
70}
71
72impl PdfBorderStyle {
73 #[must_use]
74 pub const fn from_raw(raw: i32) -> Option<Self> {
75 match raw {
76 0 => Some(Self::Solid),
77 1 => Some(Self::Dashed),
78 2 => Some(Self::Beveled),
79 3 => Some(Self::Inset),
80 4 => Some(Self::Underline),
81 _ => None,
82 }
83 }
84}
85
86#[derive(Debug, Clone, Copy, PartialEq, Eq)]
87#[repr(i32)]
88pub enum PdfActionNamedName {
89 None = 0,
90 NextPage = 1,
91 PreviousPage = 2,
92 FirstPage = 3,
93 LastPage = 4,
94 GoBack = 5,
95 GoForward = 6,
96 GoToPage = 7,
97 Find = 8,
98 Print = 9,
99 ZoomIn = 10,
100 ZoomOut = 11,
101}
102
103impl PdfActionNamedName {
104 #[must_use]
105 pub const fn as_raw(self) -> i32 {
106 self as i32
107 }
108
109 #[must_use]
110 pub const fn from_raw(raw: i32) -> Option<Self> {
111 match raw {
112 0 => Some(Self::None),
113 1 => Some(Self::NextPage),
114 2 => Some(Self::PreviousPage),
115 3 => Some(Self::FirstPage),
116 4 => Some(Self::LastPage),
117 5 => Some(Self::GoBack),
118 6 => Some(Self::GoForward),
119 7 => Some(Self::GoToPage),
120 8 => Some(Self::Find),
121 9 => Some(Self::Print),
122 10 => Some(Self::ZoomIn),
123 11 => Some(Self::ZoomOut),
124 _ => None,
125 }
126 }
127}
128
129#[derive(Debug, Clone, Copy, PartialEq, Eq)]
130#[repr(i32)]
131pub enum PdfLineStyle {
132 None = 0,
133 Square = 1,
134 Circle = 2,
135 Diamond = 3,
136 OpenArrow = 4,
137 ClosedArrow = 5,
138}
139
140impl PdfLineStyle {
141 #[must_use]
142 pub const fn from_raw(raw: i32) -> Option<Self> {
143 match raw {
144 0 => Some(Self::None),
145 1 => Some(Self::Square),
146 2 => Some(Self::Circle),
147 3 => Some(Self::Diamond),
148 4 => Some(Self::OpenArrow),
149 5 => Some(Self::ClosedArrow),
150 _ => None,
151 }
152 }
153}
154
155#[derive(Debug, Clone, Copy, PartialEq, Eq)]
156#[repr(i32)]
157pub enum PdfMarkupType {
158 Highlight = 0,
159 StrikeOut = 1,
160 Underline = 2,
161 Redact = 3,
162}
163
164impl PdfMarkupType {
165 #[must_use]
166 pub const fn from_raw(raw: i32) -> Option<Self> {
167 match raw {
168 0 => Some(Self::Highlight),
169 1 => Some(Self::StrikeOut),
170 2 => Some(Self::Underline),
171 3 => Some(Self::Redact),
172 _ => None,
173 }
174 }
175}
176
177#[derive(Debug, Clone, Copy, PartialEq, Eq)]
178#[repr(i32)]
179pub enum PdfDisplayMode {
180 SinglePage = 0,
181 SinglePageContinuous = 1,
182 TwoUp = 2,
183 TwoUpContinuous = 3,
184}
185
186impl PdfDisplayMode {
187 #[must_use]
188 pub const fn from_raw(raw: i32) -> Option<Self> {
189 match raw {
190 0 => Some(Self::SinglePage),
191 1 => Some(Self::SinglePageContinuous),
192 2 => Some(Self::TwoUp),
193 3 => Some(Self::TwoUpContinuous),
194 _ => None,
195 }
196 }
197}
198
199#[derive(Debug, Clone, Copy, PartialEq, Eq)]
200#[repr(i32)]
201pub enum PdfDisplayDirection {
202 Vertical = 0,
203 Horizontal = 1,
204}
205
206impl PdfDisplayDirection {
207 #[must_use]
208 pub const fn from_raw(raw: i32) -> Option<Self> {
209 match raw {
210 0 => Some(Self::Vertical),
211 1 => Some(Self::Horizontal),
212 _ => None,
213 }
214 }
215}
216
217#[derive(Debug, Clone, Copy, PartialEq, Eq)]
218#[repr(i32)]
219pub enum PdfInterpolationQuality {
220 None = 0,
221 Low = 1,
222 High = 2,
223}
224
225impl PdfInterpolationQuality {
226 #[must_use]
227 pub const fn from_raw(raw: i32) -> Option<Self> {
228 match raw {
229 0 => Some(Self::None),
230 1 => Some(Self::Low),
231 2 => Some(Self::High),
232 _ => None,
233 }
234 }
235}
236
237#[derive(Debug, Clone, Copy, PartialEq, Eq)]
238#[repr(i32)]
239pub enum PdfWidgetControlType {
240 Unknown = -1,
241 PushButton = 0,
242 RadioButton = 1,
243 CheckBox = 2,
244}
245
246impl PdfWidgetControlType {
247 #[must_use]
248 pub const fn from_raw(raw: i32) -> Option<Self> {
249 match raw {
250 -1 => Some(Self::Unknown),
251 0 => Some(Self::PushButton),
252 1 => Some(Self::RadioButton),
253 2 => Some(Self::CheckBox),
254 _ => None,
255 }
256 }
257}
258
259#[derive(Debug, Clone, Copy, PartialEq, Eq)]
260#[repr(i32)]
261pub enum PdfDocumentPermissions {
262 None = 0,
263 User = 1,
264 Owner = 2,
265}
266
267impl PdfDocumentPermissions {
268 #[must_use]
269 pub const fn from_raw(raw: i32) -> Option<Self> {
270 match raw {
271 0 => Some(Self::None),
272 1 => Some(Self::User),
273 2 => Some(Self::Owner),
274 _ => None,
275 }
276 }
277}
278
279#[derive(Debug, Clone, Deserialize)]
280pub struct PdfDocumentInfo {
281 pub document_url: Option<String>,
282 pub major_version: i32,
283 pub minor_version: i32,
284 pub is_encrypted: bool,
285 pub is_locked: bool,
286 pub permissions_status: i32,
287 pub access_permissions: u64,
288 pub allows_printing: bool,
289 pub allows_copying: bool,
290 pub allows_document_changes: bool,
291 pub allows_document_assembly: bool,
292 pub allows_content_accessibility: bool,
293 pub allows_commenting: bool,
294 pub allows_form_field_entry: bool,
295 pub page_class: String,
296}
297
298impl PdfDocumentInfo {
299 #[must_use]
300 pub fn permissions_status_enum(&self) -> Option<PdfDocumentPermissions> {
301 PdfDocumentPermissions::from_raw(self.permissions_status)
302 }
303}
304
305#[derive(Debug, Clone, Deserialize)]
306pub struct PdfDocumentAttributes {
307 pub title: Option<String>,
308 pub author: Option<String>,
309 pub subject: Option<String>,
310 pub creator: Option<String>,
311 pub producer: Option<String>,
312 pub creation_date: Option<String>,
313 pub modification_date: Option<String>,
314 pub keywords: Option<Vec<String>>,
315}
316
317#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)]
318pub struct PdfDocumentWriteOptions {
319 pub owner_password: Option<String>,
320 pub user_password: Option<String>,
321 pub access_permissions: Option<u64>,
322 pub burn_in_annotations: bool,
323 pub save_text_from_ocr: bool,
324 pub save_images_as_jpeg: bool,
325 pub optimize_images_for_screen: bool,
326}
327
328impl PdfDocumentWriteOptions {
329 pub fn with_owner_password(mut self, value: impl Into<String>) -> Self {
330 self.owner_password = Some(value.into());
331 self
332 }
333
334 pub fn with_user_password(mut self, value: impl Into<String>) -> Self {
335 self.user_password = Some(value.into());
336 self
337 }
338
339 pub fn with_access_permissions(mut self, value: u64) -> Self {
340 self.access_permissions = Some(value);
341 self
342 }
343
344 pub fn with_burn_in_annotations(mut self, value: bool) -> Self {
345 self.burn_in_annotations = value;
346 self
347 }
348
349 pub fn with_save_text_from_ocr(mut self, value: bool) -> Self {
350 self.save_text_from_ocr = value;
351 self
352 }
353
354 pub fn with_save_images_as_jpeg(mut self, value: bool) -> Self {
355 self.save_images_as_jpeg = value;
356 self
357 }
358
359 pub fn with_optimize_images_for_screen(mut self, value: bool) -> Self {
360 self.optimize_images_for_screen = value;
361 self
362 }
363}
364
365#[derive(Debug, Clone, Deserialize)]
366pub struct PdfBorderInfo {
367 pub style: i32,
368 pub line_width: f64,
369 pub dash_pattern: Option<Vec<f64>>,
370}
371
372impl PdfBorderInfo {
373 #[must_use]
374 pub fn style_enum(&self) -> Option<PdfBorderStyle> {
375 PdfBorderStyle::from_raw(self.style)
376 }
377}
378
379#[derive(Debug, Clone, Deserialize)]
380pub struct PdfAnnotationInfo {
381 pub annotation_type: Option<String>,
382 pub bounds: PdfRect,
383 pub contents: Option<String>,
384 pub should_display: bool,
385 pub should_print: bool,
386 pub has_appearance_stream: bool,
387 pub user_name: Option<String>,
388 pub modification_date: Option<String>,
389 pub color: Option<PdfColor>,
390 pub highlighted: bool,
391 pub action_type: Option<String>,
392 pub border: Option<PdfBorderInfo>,
393}
394
395#[derive(Debug, Clone, Deserialize)]
396pub struct PdfDestinationInfo {
397 pub page_label: Option<String>,
398 pub page_index: Option<usize>,
399 pub point: PdfPoint,
400 pub zoom: f64,
401}
402
403#[derive(Debug, Clone, Deserialize)]
404pub struct PdfAppearanceCharacteristicsInfo {
405 pub control_type: i32,
406 pub background_color: Option<PdfColor>,
407 pub border_color: Option<PdfColor>,
408 pub rotation: i32,
409 pub caption: Option<String>,
410 pub rollover_caption: Option<String>,
411 pub down_caption: Option<String>,
412}
413
414impl PdfAppearanceCharacteristicsInfo {
415 #[must_use]
416 pub fn control_type_enum(&self) -> Option<PdfWidgetControlType> {
417 PdfWidgetControlType::from_raw(self.control_type)
418 }
419}
420
421#[derive(Debug, Clone, Deserialize)]
422pub struct PdfViewInfo {
423 pub display_mode: i32,
424 pub display_direction: i32,
425 pub displays_page_breaks: bool,
426 pub page_break_margins: PdfEdgeInsets,
427 pub display_box: i32,
428 pub displays_as_book: bool,
429 pub displays_rtl: bool,
430 pub background_color: Option<PdfColor>,
431 pub interpolation_quality: i32,
432 pub page_shadows_enabled: bool,
433 pub scale_factor: f64,
434 pub min_scale_factor: f64,
435 pub max_scale_factor: f64,
436 pub auto_scales: bool,
437 pub scale_factor_for_size_to_fit: f64,
438 pub in_markup_mode: bool,
439 pub has_document_view: bool,
440 pub visible_page_count: usize,
441 pub current_page_label: Option<String>,
442}
443
444impl PdfViewInfo {
445 #[must_use]
446 pub fn display_mode_enum(&self) -> Option<PdfDisplayMode> {
447 PdfDisplayMode::from_raw(self.display_mode)
448 }
449
450 #[must_use]
451 pub fn display_direction_enum(&self) -> Option<PdfDisplayDirection> {
452 PdfDisplayDirection::from_raw(self.display_direction)
453 }
454
455 #[must_use]
456 pub fn interpolation_quality_enum(&self) -> Option<PdfInterpolationQuality> {
457 PdfInterpolationQuality::from_raw(self.interpolation_quality)
458 }
459
460 #[must_use]
461 pub fn display_box_enum(&self) -> Option<DisplayBox> {
462 match self.display_box {
463 0 => Some(DisplayBox::MediaBox),
464 1 => Some(DisplayBox::CropBox),
465 2 => Some(DisplayBox::BleedBox),
466 3 => Some(DisplayBox::TrimBox),
467 4 => Some(DisplayBox::ArtBox),
468 _ => None,
469 }
470 }
471}
472
473#[derive(Debug, Clone, Deserialize)]
474pub struct PdfThumbnailViewInfo {
475 pub has_pdf_view: bool,
476 pub background_color: Option<PdfColor>,
477 pub selected_pages_count: usize,
478 pub thumbnail_size: PdfSize,
479 pub maximum_number_of_columns: usize,
480 pub allows_dragging: bool,
481 pub allows_multiple_selection: bool,
482}