I’m running an azure function to produce images of PDFs and recently had an issue which I don’t fully understand yet. The code is running in .net core 3 on azure functions (windows, function 3 runtime)
The part that produces a weird output is pretty straightforward and looks like this:
using var document = new Document(pdfStream);
var jpegDevice = new JpegDevice(new Resolution(150), 90);
jpegDevice.Process(document.Pages[1], imageStream);
I will attach the input PDF and the output image. The output image seems mangled (like a font issue) but we can’t get a good reproduction scenario (yet), it seems to happen on certain azure functions hosts only.
Do you know what might cause these issues?
I’m using Aspose PDF 20.10.0
Edit: Not sure how to attach files, here’s a wetransfer link with both the pdf as well as the jpg image: https://we.tl/t-f7ZIDyewFL
Edit 2:
I managed to reproduce it on my own machine, could it be related to this topic: Operations that change non-concurrent collections must have exclusive access. error in Convert(Document.CallBackGetHocr) - #2 by asad.ali
This code can be used to reproduce it (make a lot of copies of the pdf file attached to simulate multiple pages in parallel:
var allFiles = Directory.GetFiles(@"C:\tmp\pages");
Parallel.ForEach(allFiles, inputfile =>
{
using var document = new Document(inputfile);
var jpegDevice = new JpegDevice(new Resolution(150), 90);
jpegDevice.Process(document.Pages[1], $"{Guid.NewGuid()}.jpg");
});
When I use Aspose.PDF 20.9 it works fine, with Aspose.PDF 20.10 every image is mangled.
One last edit: We found another workaround (for now we downgraded back to Aspose PDF 20.9) is to set RenderingOptions.MaxFontsCacheSize = 0
on the jpegDevice
, so it’s probably related to the font cache.