diff options
Diffstat (limited to 'src/core/print/plugins/pdf.rs')
| -rw-r--r-- | src/core/print/plugins/pdf.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/core/print/plugins/pdf.rs b/src/core/print/plugins/pdf.rs new file mode 100644 index 0000000..2456edb --- /dev/null +++ b/src/core/print/plugins/pdf.rs @@ -0,0 +1,27 @@ +use anyhow::{Context, Result}; +use printpdf::PdfDocumentReference; +use std::fs::File; +use std::io::BufWriter; +use std::path::PathBuf; + +pub struct PdfPlugin; + +impl PdfPlugin { + pub fn new() -> Self { + Self + } + + pub fn export_pdf(&self, doc: PdfDocumentReference, path: &PathBuf) -> Result<()> { + let file = File::create(path).context("Failed to create PDF file for export")?; + let mut writer = BufWriter::new(file); + doc.save(&mut writer) + .context("Failed to save PDF to specified path")?; + Ok(()) + } +} + +impl Default for PdfPlugin { + fn default() -> Self { + Self::new() + } +} |
