blob: 2456edb66ceeaa525fa621aee91866e9259f96d5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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()
}
}
|