开发者

fetching the 1st page of pdf as UIImage in ipad development

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();
   开发者_StackOverflow     CGContextTranslateCTM(context,0,rect.size.height);
        CGContextScaleCTM(context,scale,-scale);
        CGContextDrawPDFPage(context,pdfPage);
        UIImage* pdfImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return pdfImage;
    //}
    //return nil;
}

Thanks Shoeb


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜