1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-20 08:25:16 +00:00

Can create PDF posts

This commit is contained in:
2020-07-08 17:14:55 +02:00
parent 82b1f5e473
commit 24469101bc
7 changed files with 326 additions and 41 deletions

View File

@ -6,4 +6,5 @@ pub mod crypt_utils;
pub mod user_data_utils;
pub mod virtual_directories_utils;
pub mod date_utils;
pub mod string_utils;
pub mod string_utils;
pub mod pdf_utils;

22
src/utils/pdf_utils.rs Normal file
View File

@ -0,0 +1,22 @@
//! # PDF utilities
//!
//! @author Pierre Hubert
use crate::data::error::{ExecError, ResultBoxError};
/// Check out whether a PDF is a valid PDF or not, by trying to open it
pub fn is_valid_pdf(file: &bytes::Bytes) -> ResultBoxError<bool> {
let pdf = pdf::file::File::new(Vec::from(file.as_ref()));
match pdf.get_num_pages() {
Ok(num) if num < 1 =>
Err(ExecError::boxed_string(format!("Detected a PDF with {} pages!", num))),
Ok(_) => Ok(true),
Err(e) => {
println!("Error while parsing PDF: {}", e);
Ok(false)
}
}
}