| 1 |
use lopdf::{Document, IncrementalDocument, Result}; |
| 2 |
use std::fmt::Display; |
| 3 |
use std::path::Path; |
| 4 |
|
| 5 |
#[allow(dead_code)] |
| 6 |
pub fn load_document<P>(path: P) -> Result<Document> |
| 7 |
where |
| 8 |
P: AsRef<Path> + Display, |
| 9 |
{ |
| 10 |
#[cfg(feature = "async")] |
| 11 |
let doc = tokio::runtime::Runtime::new()? |
| 12 |
.block_on(async move { Document::load(&path).await.expect(&*format!("Failed to load {}", path)) }); |
| 13 |
#[cfg(not(feature = "async"))] |
| 14 |
let doc = Document::load(path)?; |
| 15 |
|
| 16 |
Ok(doc) |
| 17 |
} |
| 18 |
|
| 19 |
#[allow(dead_code)] |
| 20 |
pub fn load_incremental_document<P>(path: P) -> Result<IncrementalDocument> |
| 21 |
where |
| 22 |
P: AsRef<Path> + Display, |
| 23 |
{ |
| 24 |
#[cfg(feature = "async")] |
| 25 |
let doc = tokio::runtime::Runtime::new()?.block_on(async move { |
| 26 |
IncrementalDocument::load(&path) |
| 27 |
.await |
| 28 |
.expect(&*format!("Failed to load {}", path)) |
| 29 |
}); |
| 30 |
#[cfg(not(feature = "async"))] |
| 31 |
let doc = IncrementalDocument::load(path)?; |
| 32 |
|
| 33 |
Ok(doc) |
| 34 |
} |