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 677085
In Process

The Archive Base Latest Questions

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

I’m trying to draw the pages of a PDF using the code below. Some

  • 0

I’m trying to draw the pages of a PDF using the code below. Some PDF’s render correctly, but others simply show as a completely black image, or have partial portions rendered and the rest black. In comparing what’s going on, the ones that show OK seem to have always have “regular” text in them along with some graphics (diagrams, etc.), while the ones that come out black are typically all graphics (like a page of sheet music, for example). Can anyone point me in the right direction on this?
I building this on the new 3.2 SDK.

Thanks!

// PDF page drawing expects a Lower-Left coordinate system, so we flip the coordinate system
// before we start drawing.
 CGContextTranslateCTM(context, 0.0, self.bounds.size.height);
 CGContextScaleCTM(context, 1.0, -1.0);

 // Grab the first PDF page
CGPDFPageRef page = CGPDFDocumentGetPage(myPDF, pageNo);
// We're about to modify the context CTM to draw the PDF page where we want it, so save     the graphics state in case we want to do more drawing
CGContextSaveGState(context);
// CGPDFPageGetDrawingTransform provides an easy way to get the transform for a PDF page. It will scale down to fit, including any
// base rotations necessary to display the PDF page correctly. 
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, self.bounds, 0, true);
// And apply the transform.
CGContextConcatCTM(context, pdfTransform);
// Finally, we draw the page and restore the graphics state for further manipulations!
CGContextDrawPDFPage(context, page);
CGContextRestoreGState(context);
  • 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-14T01:00:00+00:00Added an answer on May 14, 2026 at 1:00 am

    CGPDFDocumentRef MyGetPDFDocumentRef (const char *filename) {
    CFStringRef path;
    CFURLRef url;
    CGPDFDocumentRef document;
    path = CFStringCreateWithCString (NULL, filename,kCFStringEncodingUTF8);
    url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, 0);
    CFRelease (path);
    document = CGPDFDocumentCreateWithURL (url);// 2
    CFRelease(url);
    int count = CGPDFDocumentGetNumberOfPages (document);// 3
    if (count == 0) {
    printf(“`%s’ needs at least one page!”, filename);
    return NULL;
    }
    return document;
    }

    void MyDisplayPDFPage (CGContextRef myContext,size_t pageNumber,const char *filename) {
        CGPDFDocumentRef document;
        CGPDFPageRef page;
        document = MyGetPDFDocumentRef (filename);// 1
        page = CGPDFDocumentGetPage (document, pageNumber);// 2
        CGContextDrawPDFPage (myContext, page);// 3
        CGContextTranslateCTM(myContext, 0, 20);
        CGContextScaleCTM(myContext, 1.0, -1.0);
        CGPDFDocumentRelease (document);// 4
    }
    
    
    
    #import "DashBoard.h"
    
    #import <QuartzCore/QuartzCore.h>
    
    @interface UIImage (WBImage)
    // rotate UIImage to any angle
    -(UIImage*)rotate:(UIImageOrientation)orient;
    @end
    
    @implementation UIImage (WBImage)
    
    
    static inline CGFloat degreesToRadians(CGFloat degrees)
    {
        return M_PI * (degrees / 180.0);
    }
    
    static inline CGSize swapWidthAndHeight(CGSize size)
    {
        CGFloat  swap = size.width;
    
        size.width  = size.height;
        size.height = swap;
    
        return size;
    }
    
    
    -(UIImage*)rotate:(UIImageOrientation)orient
    {
        CGRect             bnds = CGRectZero;
        UIImage*           copy = nil;
        CGContextRef       ctxt = nil;
        CGRect             rect = CGRectZero;
        CGAffineTransform  tran = CGAffineTransformIdentity;
    
        bnds.size = self.size;
        rect.size = self.size;
    
        switch (orient)
        {
            case UIImageOrientationUp:
                return self;
    
            case UIImageOrientationUpMirrored:
                tran = CGAffineTransformMakeTranslation(rect.size.width, 0.0);
                tran = CGAffineTransformScale(tran, -1.0, 1.0);
                break;
    
            case UIImageOrientationDown:
                tran = CGAffineTransformMakeTranslation(rect.size.width,
                                                        rect.size.height);
                tran = CGAffineTransformRotate(tran, degreesToRadians(180.0));
                break;
    
            case UIImageOrientationDownMirrored:
                tran = CGAffineTransformMakeTranslation(0.0, rect.size.height);
                tran = CGAffineTransformScale(tran, 1.0, -1.0);
                break;
    
            case UIImageOrientationLeft:
                bnds.size = swapWidthAndHeight(bnds.size);
                tran = CGAffineTransformMakeTranslation(0.0, rect.size.width);
                tran = CGAffineTransformRotate(tran, degreesToRadians(-90.0));
                break;
    
            case UIImageOrientationLeftMirrored:
                bnds.size = swapWidthAndHeight(bnds.size);
                tran = CGAffineTransformMakeTranslation(rect.size.height,
                                                        rect.size.width);
                tran = CGAffineTransformScale(tran, -1.0, 1.0);
                tran = CGAffineTransformRotate(tran, degreesToRadians(-90.0));
                break;
    
            case UIImageOrientationRight:
                bnds.size = swapWidthAndHeight(bnds.size);
                tran = CGAffineTransformMakeTranslation(rect.size.height, 0.0);
                tran = CGAffineTransformRotate(tran, degreesToRadians(90.0));
                break;
    
            case UIImageOrientationRightMirrored:
                bnds.size = swapWidthAndHeight(bnds.size);
                tran = CGAffineTransformMakeScale(-1.0, 1.0);
                tran = CGAffineTransformRotate(tran, degreesToRadians(90.0));
                break;
    
            default:
                // orientation value supplied is invalid
                assert(false);
                return nil;
        }
    
        UIGraphicsBeginImageContext(bnds.size);
        ctxt = UIGraphicsGetCurrentContext();
    
        switch (orient)
        {
            case UIImageOrientationLeft:
            case UIImageOrientationLeftMirrored:
            case UIImageOrientationRight:
            case UIImageOrientationRightMirrored:
                CGContextScaleCTM(ctxt, -1.0, 1.0);
                CGContextTranslateCTM(ctxt, -rect.size.height, 0.0);
                break;
    
            default:
                CGContextScaleCTM(ctxt, 1.0, -1.0);
                CGContextTranslateCTM(ctxt, 0.0, -rect.size.height);
                break;
        }
    
        CGContextConcatCTM(ctxt, tran);
        CGContextDrawImage(ctxt, rect, self.CGImage);
    
        copy = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return copy;
    }
    
    
    @end
    
    
    
    
    @implementation DashBoard
    
    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
        [super viewDidLoad];
        filePath=[[NSString alloc] initWithString:[[NSBundle mainBundle] pathForResource:@"roadie" ofType:@"pdf"]];
    
        // an IBOutlet UIScrollView
        [scrMain setContentSize:CGSizeMake(720, 720)];
        // an IBOutlet UIImageView
        [imgV setFrame:CGRectMake(0, 0, 720, 720)];
        UIGraphicsBeginImageContext(CGSizeMake(720, 720));
        // initial page is an size_t variable
        initialPage=1;
        MyDisplayPDFPage(UIGraphicsGetCurrentContext(), initialPage, [filePath UTF8String],myTable,mainString);
        imgV.image=UIGraphicsGetImageFromCurrentImageContext();
        imgV.image=[imgV.image rotate:UIImageOrientationDownMirrored];
    }
    

    Just copy & paste above code. It will work for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.