Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6910169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:46:47+00:00 2026-05-27T08:46:47+00:00

I have an app that’s basically a fancy PDF reader. I download a PDF

  • 0

I have an app that’s basically a fancy PDF reader. I download a PDF from the internet and generate thumbnails for that PDF. However, it seems that when I generate these thumbnails a lot of memory is being allocated (checked using Instruments), sometimes parts of this is collected by the GC but in the end, my app gives up. I’ve had memory usage of up to 38Mb when generating thumbnails for a single PDF (100×100 thumbs, ~60 pages).

I generate one thumbnail at a time, store it and then repeat the process, so under any circumstance there should only be one thumbnail in memory (while generating them, at least). My code for generating thumbnails looks like this:

public UIImage GetPageThumbnail(int pageNumber, SizeF size)
{
    //If using retina display, make sure to scale-up the thumbnail as well.
    size.Width = size.Width * UIScreen.MainScreen.Scale;
    size.Height = size.Height * UIScreen.MainScreen.Scale;

    UIGraphics.BeginImageContext(size);
    CGContext tempContext = UIGraphics.GetCurrentContext();
    CGPDFPage page = Document.GetPage(pageNumber);

    RectangleF drawArea = new RectangleF(new PointF(0f, 0f), size);
    CGAffineTransform transform = page.GetDrawingTransform( CGPDFBox.Crop, drawArea, 180, true); //fit PDF to context
    transform.xx = -transform.xx;   // }
    transform.x0 = 0;               // }flip horizontally

    //Console.WriteLine("XX: " + transform.xx + ", YX:" + transform.yx + ", XY:" + transform.xy + ", YY:" + transform.yy + ", X0:" + transform.x0 + ", Y0:" + transform.y0);

    tempContext.ConcatCTM(transform);

    tempContext.DrawPDFPage (page);
    UIImage returnImage = UIGraphics.GetImageFromCurrentImageContext();
    UIGraphics.EndImageContext();
    return returnImage;
}

I’ve tried explicitly disposing the context and PDF page, but that had no effect (actually it seemed worse, but take that with a pinch of salt).

I’ve seen some posts about memory leakage with MonoTouch and PDF (basically this post), but that’s pretty old. I’m using the newest MonoTouch (5.0.2).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:46:48+00:00Added an answer on May 27, 2026 at 8:46 am

    Not sure where the problem in your code is, but here’s my code for generating thumbs of PDF pages. It is working flawlessly. Maybe it helps you. I think your issue might be what you are doing with the returned image when you’re don.

    public static UIImageView GetLowResPagePreview (CGPDFPage oPdfPage, RectangleF oTargetRect)
            {
                RectangleF oOriginalPdfPageRect = oPdfPage.GetBoxRect (CGPDFBox.Media);
                RectangleF oPdfPageRect = PdfViewerHelpers.RotateRectangle( oPdfPage.GetBoxRect (CGPDFBox.Media), oPdfPage.RotationAngle);
    
                // Create a low res image representation of the PDF page to display before the TiledPDFView
                // renders its content.
                int iWidth = Convert.ToInt32 ( oPdfPageRect.Size.Width );
                int iHeight = Convert.ToInt32 ( oPdfPageRect.Size.Height );
                CGColorSpace oColorSpace = CGColorSpace.CreateDeviceRGB();
                CGBitmapContext oContext = new CGBitmapContext(null, iWidth, iHeight, 8, iWidth * 4, oColorSpace, CGImageAlphaInfo.PremultipliedLast);
    
                // First fill the background with white.
                oContext.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f);
                oContext.FillRect (oOriginalPdfPageRect);
                // Scale the context so that the PDF page is rendered 
                // at the correct size for the zoom level.
                oContext.ConcatCTM ( oPdfPage.GetDrawingTransform ( CGPDFBox.Media, oPdfPageRect, 0, true ) );
                oContext.DrawPDFPage (oPdfPage);
                CGImage oImage = oContext.ToImage();
                UIImage oBackgroundImage = UIImage.FromImage( oImage );
                oContext.Dispose();
                oImage.Dispose ();
                oColorSpace.Dispose ();
    
                UIImageView oBackgroundImageView = new UIImageView (oBackgroundImage);
                oBackgroundImageView.Frame = new RectangleF (new PointF (0, 0), oPdfPageRect.Size);
                oBackgroundImageView.ContentMode = UIViewContentMode.ScaleToFill;
                oBackgroundImageView.UserInteractionEnabled = false;
                oBackgroundImageView.AutoresizingMask = UIViewAutoresizing.None;
                return oBackgroundImageView;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that would benefit from google-style autocompletion while filling in an
I have an app that uses core data. The app is free for download
I have an app that builds XML, the text nodes values are coming from
I have an app that needs to read in and evaluate expressions from a
I have an app that was created using .net Framework 3.5. However, I now
have an app that finds your GPS location successfully, but I need to be
Have an app that has listings - think classified ads - and each listing
I have an app that needs to open a new window (in the same
I have an app that executes commands on a Linux server via SSH just
I have a app that I'm deploying to a development server using Capistrano. I'd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.