|
|
|
@ -12,7 +12,8 @@ use crate::settings::Settings;
|
|
|
|
|
use crate::utils::caching::CacheStorage;
|
|
|
|
|
use bibliographix::Mutex;
|
|
|
|
|
use headless_chrome::protocol::page::PrintToPdfOptions;
|
|
|
|
|
use headless_chrome::{Browser, LaunchOptionsBuilder, Tab};
|
|
|
|
|
use headless_chrome::{Browser, Tab};
|
|
|
|
|
use std::env;
|
|
|
|
|
use std::fs;
|
|
|
|
|
use std::fs::OpenOptions;
|
|
|
|
|
use std::io::BufWriter;
|
|
|
|
@ -26,8 +27,14 @@ pub mod result;
|
|
|
|
|
/// Renders the document to pdf and returns the resulting bytes
|
|
|
|
|
pub fn render_to_pdf(document: Document) -> PdfRenderingResult<Vec<u8>> {
|
|
|
|
|
let cache = CacheStorage::new();
|
|
|
|
|
let mut file_path = PathBuf::from(format!("tmp-document.html"));
|
|
|
|
|
let mut file_path = PathBuf::from("tmp-document.html");
|
|
|
|
|
file_path = cache.get_file_path(&file_path);
|
|
|
|
|
|
|
|
|
|
if !file_path.parent().map(|p| p.exists()).unwrap_or(false) {
|
|
|
|
|
file_path = env::current_dir()?;
|
|
|
|
|
file_path.push(PathBuf::from(".tmp-document.html"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let config = document.config.clone();
|
|
|
|
|
let mathjax = config.lock().features.include_mathjax;
|
|
|
|
|
|
|
|
|
@ -50,7 +57,7 @@ pub fn render_to_pdf(document: Document) -> PdfRenderingResult<Vec<u8>> {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let browser = Browser::new(LaunchOptionsBuilder::default().build().unwrap())?;
|
|
|
|
|
let browser = Browser::default()?;
|
|
|
|
|
let tab = browser.wait_for_initial_tab()?;
|
|
|
|
|
handle.join().unwrap()?;
|
|
|
|
|
tab.navigate_to(format!("file:///{}", file_path.to_string_lossy()).as_str())?;
|
|
|
|
|