The application crashes when an image of a certain PDF (50 MB, 1 page) is drawn on the context page in background.

Hi Team, I am using CGPDFPage and CGContext to convert the PDF to an image. It is working fine in all circumstances but fails in one circumstance where the size of the PDF is above 50 MB and when the application is made to be on background and again opened. It is also occurring only on physical devices; emulators are working fine. We are using the following code for this conversation:

fileStream.CopyTo(memoryStream);
CGDataProvider provider = new CGDataProvider(memoryStream.ToArray());
CGPDFDocument cGPDFDocument = null;
 image = null;
    cGPDFDocument = new CGPDFDocument(provider);
using(CGPDFPage pdfPage = cGPDFDocument?.GetPage(1))
{
     if (pdfPage != null)

    {
        CGRect rect = pdfPage.GetBoxRect(CGPDFBox.Media);
        if (pdfPage.RotationAngle == 90 || pdfPage.RotationAngle == 270)
        {
            rect = new CGRect(rect.X, rect.Y, rect.Height, rect.Width);
        }
        nfloat factor = (nfloat)0.5;
        CGRect bounds = new CGRect(rect.X * factor, rect.Y * factor, rect.Width * factor, rect.Height * factor);
        UIGraphics.BeginImageContext(bounds.Size);
        CGContext context = UIGraphics.GetCurrentContext();
        context.SetFillColor(1.0f, 1.0f, 1.0f, 1.0f);
        context.FillRect(bounds);
        context.TranslateCTM(0, bounds.Height);
        context.ScaleCTM(factor, -factor);
        context.ConcatCTM(pdfPage.GetDrawingTransform(CGPDFBox.Crop, rect, 0, true));
        context.SetRenderingIntent(CGColorRenderingIntent.Default);
        context.InterpolationQuality = CGInterpolationQuality.Default;
        context.DrawPDFPage(pdfPage);
        image = UIGraphics.GetImageFromCurrentImageContext();
        UIGraphics.EndImageContext();
        imageView.Image = image; 
        parentView.AddSubview(imageView);
    }
}

We have added a simple application created on Xamarin.iOS platform that replicates this issue in Assets we have added the PDF with this issue https://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfToImageSample-556012354

We have recorded this for the reference, https://www.syncfusion.com/downloads/support/directtrac/general/ze/CrashBGImgRec-1376481150

This issue is constantly occurring on the "context.DrawPDFPage(pdfPage);" line in my application. On the provided sample, this issue is occurring consistently when the break point is placed on the "context.DrawPDFPage(pdfPage);" line. It also occurs randomly without placing the breakpoint.

We are invoking this function on DidEnterBackground override method of AppDelegate

Do we need to set any to properly retrieve the image from CGPDFPage and add them into context?

Hi team, Could you please let us know about this issuse?

The application crashes when an image of a certain PDF (50 MB, 1 page) is drawn on the context page in background.
 
 
Q