If azure stream is passed to Conversion.ToImages then conversion fails with an error. However it succeeds if azure stream is copied to file system first and FileStream is used instead. The problem does not occur for all pdf files, only specific ones (link below).
Tried PDFtoImage and Syncfusion.PdfToImageConverter.Net libraries which are based on pdfium engine and both fail with same error.
Example code provided using PDFtoImage
public async Task<List<SKBitmap>> TestConvertPdfToImagesAsync()
{
var blobServiceClient = new BlobServiceClient("?");
BlobClient blobClient = blobServiceClient
.GetBlobContainerClient("test")
.GetBlobClient("map.pdf");
var bitmaps = new List<SKBitmap>();
using (Stream pdfStream = await blobClient.OpenReadAsync())
{
foreach (SKBitmap bitmap in Conversion.ToImages(pdfStream, true, null, new RenderOptions { Dpi = 220 }))
{
bitmaps.Add(bitmap);
}
}
return bitmaps;
}
This is the error I'm receiving
System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception. at PDFtoImage.Internals.NativeMethods.Imports.FPDF_LoadPage(IntPtr document, Int32 page_index) at PDFtoImage.Internals.NativeMethods.FPDF_LoadPage(IntPtr document, Int32 page_index) at PDFtoImage.Internals.PdfFile.PageData..ctor(IntPtr document, IntPtr form, Int32 pageNumber) at PDFtoImage.Internals.PdfFile.RenderPDFPageToBitmap(Int32 pageNumber, IntPtr bitmapHandle, Int32 boundsOriginX, Int32 boundsOriginY, Int32 boundsWidth, Int32 boundsHeight, Int32 rotate, FPDF flags, Boolean renderFormFill) at PDFtoImage.Internals.PdfDocument.RenderSubset(PdfFile file, Int32 page, Single width, Single height, PdfRotation rotate, FPDF flags, Boolean renderFormFill, SKColor backgroundColor, Nullable
1 bounds, Single originalWidth, Single originalHeight, CancellationToken cancellationToken) at PDFtoImage.Internals.PdfDocument.Render(Int32 page, Nullable1 requestedWidth, Nullable1 requestedHeight, Single dpiX, Single dpiY, PdfRotation rotate, FPDF flags, Boolean renderFormFill, SKColor backgroundColor, Nullable1 bounds, Boolean useTiling, Boolean withAspectRatio, Boolean dpiRelativeToBounds, CancellationToken cancellationToken) at PDFtoImage.Conversion.RenderImpl(PdfDocument pdfDocument, Int32 page, FPDF renderFlags, RenderOptions options) at PDFtoImage.Conversion.ToImagesImpl(PdfDocument pdfDocument, RenderOptions options, IEnumerable1 pages)+MoveNext() at PDFtoImage.Conversion.ToImagesImpl(Stream pdfStream, Boolean leaveOpen, String password, RenderOptions options, IEnumerable1 pages)+MoveNext() at PDFtoImage.Conversion.ToImages(Stream pdfStream, IEnumerable`1 pages, Boolean leaveOpen, String password, RenderOptions options)+MoveNext() at Biometric.Tests.Tests.PdfToImageCovert()


MemoryStreamor temporary file first before passing it toConversion.ToImages.