use beet::prelude::*;
#[derive(Debug, Clone)]
pub struct ExportPdf {
pub no_margin: bool,
pub input: String,
pub output: std::path::PathBuf,
pub page_ranges: Vec<String>,
}
impl Default for ExportPdf {
fn default() -> Self {
Self {
no_margin: false,
input: String::new(),
output: "file.pdf".into(),
page_ranges: Vec::new(),
}
}
}
impl ExportPdf {
#[allow(unused)]
pub async fn run(self) -> Result {
App::default()
.run_io_task_local(async move {
let mut opts = PdfOptions {
page_ranges: self.page_ranges,
..default()
};
if self.no_margin {
opts.margin = PdfMargin::none();
}
let (proc, page) = Page::visit(&self.input).await?;
let bytes = page.export_pdf_with_options(&opts).await?;
fs_ext::write_async(self.output, bytes).await?;
Ok(())
})
.await
}
}