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

  • SEARCH
  • Home
  • 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 3662486
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:25:19+00:00 2026-05-19T01:25:19+00:00

I’m trying to render a CGPDFPage (selected from a CGPDFDocument) into a UIImage to

  • 0

I’m trying to render a CGPDFPage (selected from a CGPDFDocument) into a UIImage to display on a view.

I have the following code in MonoTouch which gets me part way there.

RectangleF PDFRectangle = new RectangleF(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);

    public override void ViewDidLoad ()
    {
        UIGraphics.BeginImageContext(new SizeF(PDFRectangle.Width, PDFRectangle.Height));
        CGContext context = UIGraphics.GetCurrentContext();
        context.SaveState();

        CGPDFDocument pdfDoc = CGPDFDocument.FromFile("test.pdf");
        CGPDFPage pdfPage = pdfDoc.GetPage(1);  

        context.DrawPDFPage(pdfPage);
        UIImage testImage = UIGraphics.GetImageFromCurrentImageContext();

        pdfDoc.Dispose();
        context.RestoreState();

        UIImageView imageView = new UIImageView(testImage);
        UIGraphics.EndImageContext();

        View.AddSubview(imageView);
    }

A section of the CGPDFPage is displayed but rotated back-to-front and upside down. My question is, how do I select the full pdf page and flip it round to display correctly. I have seen a few examples using ScaleCTM and TranslateCTM but couldn’t seem to get them working.

Any examples in ObjectiveC are fine, I’ll take all the help I can get 🙂

Thanks

  • 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-19T01:25:20+00:00Added an answer on May 19, 2026 at 1:25 am

    I haven’t worked with MonoTouch. However, in objective-C you would get an image for a PDF page like this (notice the CTM transforms):

    -(UIImage *)getThumbForPage:(int)page_number{
     CGFloat width = 60.0;
    
        // Get the page
     CGPDFPageRef myPageRef = CGPDFDocumentGetPage(myDocumentRef, page);
     // Changed this line for the line above which is a generic line
     //CGPDFPageRef page = [self getPage:page_number];
    
     CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
     CGFloat pdfScale = width/pageRect.size.width;
     pageRect.size = CGSizeMake(pageRect.size.width*pdfScale, pageRect.size.height*pdfScale);
     pageRect.origin = CGPointZero;
    
    
     UIGraphicsBeginImageContext(pageRect.size);
    
     CGContextRef context = UIGraphicsGetCurrentContext();
    
     // White BG
     CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
     CGContextFillRect(context,pageRect);
    
     CGContextSaveGState(context);
    
        // ***********
     // Next 3 lines makes the rotations so that the page look in the right direction
        // ***********
     CGContextTranslateCTM(context, 0.0, pageRect.size.height);
     CGContextScaleCTM(context, 1.0, -1.0);
     CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, pageRect, 0, true));
    
     CGContextDrawPDFPage(context, page);
     CGContextRestoreGState(context);
    
     UIImage *thm = UIGraphicsGetImageFromCurrentImageContext();
    
     UIGraphicsEndImageContext();
     return thm;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view passing on information from a database: def serve_article(request, id): served_article
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from

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.