Hello,
we’re using Aspose.PDF (C#) to render PDF-Pages to PNG for a preview function in our application.
User report state, that for some documents this takes excessive time (~10-20s). We could reproduce this issue on our dev machines with sample documents taking ~8s to render a single page.
Pdf Viewers like Adobe Reader or Edge open these documents just fine without any real delay.
It seems like the problematic documents have in common, that they contain a single image (photograph) beeing converted to a pdf with a very big page size. The size of the image in pixels does not seem to be that relevant for this issue.
Due to privacy reasons we can’t provide a real document, but we managed to create one using an online PDF converter that behaves close to what we see with user documents (although not as slow with around 3s conversion for a single page on our machines).
The RenderingOptions of the PngDevice do not seem to affect performance in any way (except of OptimizeDimensions which roughly doubles the time), also the resolution is not relevant.
A simple way to reproduce this is as follows:
using System.Diagnostics;
using Aspose.Pdf;
License pdfLicense = new();
//TODO Load License
using MemoryStream pdfStream = new(File.ReadAllBytes("slow_convert_sample.pdf"));
using Document document = new(pdfStream);
for (int i = 0; i < 3; i++)
{
foreach (Page page in document.Pages)
{
Stopwatch sw = Stopwatch.StartNew();
using MemoryStream ms = page.ConvertToPNGMemoryStream();
sw.Stop();
Console.WriteLine(sw.Elapsed);
}
}
slow_convert_sample.pdf (1,5 MB)