0

In ipad development is there a way to get the 1st page of a pdf file as UIImage??? if u dont have the exact solution now can u tell me which way should I proceed??

I tried this function..but UIGraphicsGetCurrentContext() returns nothing...

+(UIImage*) imageFromPDF:(CGPDFDocumentRef)pdf withPageNumber:(NSUInteger)pageNumber withScale:(CGFloat)scale
{
    //if(pageNumber > 0 && pageNumber < CGPDFDocumentGetNumberOfPages(pdf))
    //{
        CGPDFPageRef pdfPage = CGPDFDocumentGetPage(pdf,pageNumber);
        CGRect tmpRect = CGPDFPageGetBoxRect(pdfPage,kCGPDFMediaBox);
        CGRect rect = CGRectMake(tmpRect.origin.x,tmpRect.origin.y,tmpRect.size.width*scale,tmpRect.size.height*scale);
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextTranslateCTM(context,0,rect.size.height);
        CGContextScaleCTM(context,scale,-scale);
        CGContextDrawPDFPage(context,pdfPage);
        UIImage* pdfImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return pdfImage;
    //}
    //return nil;
}

Thanks Shoeb

borrible
  • 17,120
  • 7
  • 53
  • 75
Shoeb Amin
  • 599
  • 1
  • 8
  • 18

1 Answers1

0

Here's a category I found on gist to do what you want:

https://gist.github.com/892868

Additionally, here is a post/answer from the past on SO:

Rendering a CGPDFPage into a UIImage

Community
  • 1
  • 1
shawnwall
  • 4,549
  • 1
  • 27
  • 38
  • the catagory gives the strange link error createPDFDocumentWithName in UIImage+imageWithPdfNamed.o Symbols not found – Shoeb Amin Aug 19 '11 at 13:56
  • Are you linking against any required libraries, such as CoreGraphics (I'm guessing on the required libs)? – shawnwall Aug 23 '11 at 12:52
  • Have you resolved your issue yet, or are you still seeing the link error? I would go through and make sure all required libraries are linked to in your project. Are you using a workspace with nested projects by any chance? – shawnwall Aug 25 '11 at 14:26
  • Hi shawnwall i am also trying same thumbnail generation but not at all finding how to make please give some suggestion on http://stackoverflow.com/questions/8652472/pdf-to-image-creation-in-ios this – ajay Dec 28 '11 at 08:06