From ad5ae9fb187500e7c1195844c42e2dedf2b611b2 Mon Sep 17 00:00:00 2001 From: tuancoltech Date: Mon, 4 Dec 2023 22:44:57 +0700 Subject: [PATCH 1/2] [debug] Adding debug log for debugging pdf preview crash --- src/pdf.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pdf.rs b/src/pdf.rs index 1063a6e..9ad4bb9 100644 --- a/src/pdf.rs +++ b/src/pdf.rs @@ -7,6 +7,7 @@ use std::{ use image::DynamicImage; use once_cell::sync::OnceCell; use pdfium_render::prelude::*; +use log::debug; static PDFIUM: OnceCell = OnceCell::new(); // static initializers must impl Sync + Send @@ -36,17 +37,23 @@ pub fn render_preview_page(data: R, quailty: PDFQuality) -> DynamicImage where R: Read + Seek + 'static, { + debug!("render_preview_page PDF 1"); let render_cfg = PdfRenderConfig::new(); + debug!("render_preview_page PDF 2"); let render_cfg = match quailty { PDFQuality::High => render_cfg.set_target_width(2000), PDFQuality::Medium => render_cfg, PDFQuality::Low => render_cfg.thumbnail(50), } .rotate_if_landscape(PdfBitmapRotation::Degrees90, true); + debug!("render_preview_page PDF 3"); if PDFIUM.get().is_none() { + debug!("render_preview_page PDF 4"); initialize_pdfium(); + debug!("render_preview_page PDF 5"); } + debug!("render_preview_page PDF 6"); PDFIUM .get() .unwrap() From ca1efa9269dadf80161f166cddaae6616dd04fe0 Mon Sep 17 00:00:00 2001 From: tuancoltech Date: Tue, 12 Dec 2023 21:10:56 +0700 Subject: [PATCH 2/2] Set the Medium PDFQuality render configure to 50 pixels to prevent a crash with Medium profile: render_preview_page --- src/pdf.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pdf.rs b/src/pdf.rs index 9ad4bb9..000966f 100644 --- a/src/pdf.rs +++ b/src/pdf.rs @@ -42,7 +42,7 @@ where debug!("render_preview_page PDF 2"); let render_cfg = match quailty { PDFQuality::High => render_cfg.set_target_width(2000), - PDFQuality::Medium => render_cfg, + PDFQuality::Medium => render_cfg.thumbnail(50), PDFQuality::Low => render_cfg.thumbnail(50), } .rotate_if_landscape(PdfBitmapRotation::Degrees90, true);