Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="DeterministicPdf" Version="2.3.0" />
<PackageVersion Include="Morph.PDFium" Version="1.4.2" />
<PackageVersion Include="Morph.PDFium" Version="1.4.3" />
<PackageVersion Include="MarkdownSnippets.MsBuild" Version="28.5.1" />
<PackageVersion Include="ProjectDefaults" Version="1.0.184" />
<PackageVersion Include="ProjectFiles" Version="1.6.0" />
Expand Down
40 changes: 26 additions & 14 deletions src/Verify.PDFium/VerifyPDFium.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,39 @@ static ConversionResult Convert(Stream stream, IReadOnlyDictionary<string, objec
using (var document = PdfiumDocument.Load(bytes))
{
conversion.Info = PdfProperties.Normalize(document.GetProperties());
foreach (var number in conversion.Pages(document.PageCount))
{
var index = number - 1;
using var page = document.LoadPage(index);
var size = page.Size;

Stream? image = null;
if (includeImages)
// The pages are rendered and read in parallel: PDFium works on one at a time, but each
// page's PNG encoding overlaps the others' work. The results come back in page order, so
// they are added to the conversion in order from this thread.
var indices = conversion.Pages(document.PageCount).Select(_ => _ - 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
{
Expand Down
Loading