pub mod bbox;
pub mod content_filter;
pub mod crop;
pub mod error;
#[cfg(not(target_arch = "wasm32"))]
pub mod ghostscript;
pub mod margins;
pub mod pdf_ops;
#[cfg(target_arch = "wasm32")]
pub mod wasm;
pub use bbox::{detect_bbox, BoundingBox};
pub use crop::crop_pdf;
pub use error::{Error, Result};
pub use margins::Margins;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BBoxMethod {
Ghostscript,
ContentStream,
Auto,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PageRange {
All,
Single(usize),
Range(usize, usize),
List(Vec<usize>),
}
impl PageRange {
pub fn contains(&self, page_num: usize) -> bool {
match self {
PageRange::All => true,
PageRange::Single(p) => page_num == *p,
PageRange::Range(start, end) => page_num >= *start && page_num <= *end,
PageRange::List(pages) => pages.contains(&page_num),
}
}
pub fn to_page_list(&self, total_pages: usize) -> Vec<usize> {
match self {
PageRange::All => (0..total_pages).collect(),
PageRange::Single(p) => {
if *p < total_pages {
vec![*p]
} else {
Vec::new()
}
}
PageRange::Range(start, end) => {
let start = (*start).min(total_pages.saturating_sub(1));
let end = (*end).min(total_pages.saturating_sub(1));
(start..=end).collect()
}
PageRange::List(pages) => pages
.iter()
.filter(|&&p| p < total_pages)
.copied()
.collect(),
}
}
}
#[derive(Debug, Clone)]
pub struct CropOptions {
pub margins: Margins,
pub bbox_override: Option<BoundingBox>,
pub bbox_odd: Option<BoundingBox>,
pub bbox_even: Option<BoundingBox>,
pub page_bboxes: Option<std::collections::HashMap<usize, BoundingBox>>,
pub page_range: Option<PageRange>,
pub bbox_method: BBoxMethod,
pub verbose: bool,
pub clip_content: bool,
pub shrink_to_content: bool,
}
impl Default for CropOptions {
fn default() -> Self {
Self {
margins: Margins::none(),
bbox_override: None,
bbox_odd: None,
bbox_even: None,
page_bboxes: None,
page_range: None, bbox_method: BBoxMethod::ContentStream, verbose: false,
clip_content: false, shrink_to_content: false, }
}
}