PdfViewerControl on Azure Exception

Hi,

I am utilizing the PdfViewerControl and PdfLoadedDocument classes to generate thumbnail images of a pdf. However, once I moved the project to an Azure App Service, the PdfViewerControl is throwing an exception when being initialized. I am curious if it is attempting to use system memory and Azure is blocking this. Below is the method GenerateThumbnails I've created and the exception is being thrown when creating a new PdfViewerControl. 

Method:
public static List<Byte[]> GenerateThumbnails(Byte[] file)
{
Int32 resizedHeight;
Int32 resizedWidth;
List<Byte[]> thumbnails = new List<Byte[]>();

using (PdfViewerControl pdfViewerControl = new PdfViewerControl())
using (PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(file, true))
{
// The PDF Viewer Control must load the PDF from a PdfLoadedDocument, rather than directly from the filename because
// when loaded from the filename, it is not disposed correctly and causes a file lock.
pdfViewerControl.Load(pdfLoadedDocument);

for (Int32 i = 0; i < pdfViewerControl.PageCount; ++i)
{
using (Bitmap originalBitmap = pdfViewerControl.ExportAsImage(i))
{
if (pdfViewerControl.LoadedDocument.Pages[i].Size.Width > pdfViewerControl.LoadedDocument.Pages[i].Size.Height)
{
resizedHeight = (PdfUtility.TARGET_THUMBNAIL_WIDTH_LANDSCAPE * originalBitmap.Height) / originalBitmap.Width;
resizedWidth = PdfUtility.TARGET_THUMBNAIL_WIDTH_LANDSCAPE;
}
else
{
resizedHeight = PdfUtility.TARGET_THUMBNAIL_HEIGHT_PORTRAIT;
resizedWidth = (PdfUtility.TARGET_THUMBNAIL_HEIGHT_PORTRAIT * originalBitmap.Width) / originalBitmap.Height;
}

using (Bitmap resizedBitmap = new Bitmap(originalBitmap, new Size(resizedWidth, resizedHeight)))
using (MemoryStream memoryStream = new MemoryStream())
{
resizedBitmap.Save(memoryStream, ImageFormat.Jpeg);

thumbnails.Add(memoryStream.ToArray());
}
}
}
}

return thumbnails;
}

Exception:
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

3 Replies

KK Karthik Krishnaraj Syncfusion Team August 29, 2018 09:56 AM UTC

Hi Stevan, 
 
A support incident to track the details of “PdfViewer control exceptions in azure” has been created under your account. Please log on to our support website to check for further updates. 
 
   
Please let me know if you have any questions  
 
Regards, 
Karthik. 



LO Lars Olsson September 18, 2018 01:49 PM UTC

Hi Steven,
Did you resolve this? I have a very similar issue but with another component.
If you discovered some fix, I would be very grateful if you could contact me.
Best regards
Lars


KK Karthik Krishnaraj Syncfusion Team September 19, 2018 11:10 AM UTC

Hi Steven, 
 
Could you please be more specific in which component you have faced the issue? It will be helpful for us to provide better solution. 
 
Regards, 
Karthik.  


Loader.
Up arrow icon