From e12cc1677a48b0830d936b5f37c7ba719bc146fd Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Oct 2026 13:40:10 +1100 Subject: [PATCH] Morph.PDFium 1.4.3; convert pages in parallel Convert rendered and read pages one at a time, loading each page twice (once for its text, once inside RenderPage). It now goes through PdfiumDocument.ProcessPages: each wanted page is loaded once, rendered with page.Render and read, with the pages spread across cores; the results come back in page order and are added to the conversion from this thread, so PagedConversion need not be thread safe. Morph.PDFium 1.4.3 also brings grayscale PNGs for text pages, pooled render buffers and a per-image filter choice. Measured on a 149 page text document, converting the whole document went from 1.28 s to 0.72 s at 96 DPI and 3.35 s to 1.45 s at 200 DPI. The PNGs are different bytes but compare equal under SSIM, so no snapshots change. --- src/Directory.Packages.props | 2 +- src/Verify.PDFium/VerifyPDFium.cs | 40 ++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index a7cf18d..aee0b6c 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -5,7 +5,7 @@ - + diff --git a/src/Verify.PDFium/VerifyPDFium.cs b/src/Verify.PDFium/VerifyPDFium.cs index 5a3220e..ebcecb0 100644 --- a/src/Verify.PDFium/VerifyPDFium.cs +++ b/src/Verify.PDFium/VerifyPDFium.cs @@ -104,27 +104,39 @@ static ConversionResult Convert(Stream stream, IReadOnlyDictionary _ - 1); + var pages = document.ProcessPages( + indices, + _ => { - image = new MemoryStream(document.RenderPage(index, dpi)); - } + byte[]? image = null; + if (includeImages) + { + image = _.Render(dpi); + } - string? text = null; - if (includeText) + string? text = null; + if (includeText) + { + text = _.GetText(); + } + + return (Number: _.Index + 1, _.Size, Image: image, Text: text); + }); + foreach (var (number, size, image, text) in pages) + { + Stream? imageStream = null; + if (image != null) { - text = page.GetText(); + imageStream = new MemoryStream(image); } conversion.AddPage( number, - image, + imageStream, text, new PageSize {