首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ipad开发中获取pdf的第一页作为UIImage

在ipad开发中获取pdf的第一页作为UIImage
EN

Stack Overflow用户
提问于 2011-08-18 01:10:54
回答 1查看 452关注 0票数 0

在ipad开发中,有没有一种方法可以得到pdf文件的第一页作为UIImage?如果你现在没有确切的解决方案,你能告诉我我应该怎么做吗?

我试过这个function..but UIGraphicsGetCurrentContext()不返回任何东西...

代码语言:javascript
复制
+(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;
}

谢谢Shoeb

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-18 03:03:36

这是我在gist上找到的一个类别,可以做你想做的事情:

https://gist.github.com/892868

此外,这是关于SO的过去的帖子/答案:

Rendering a CGPDFPage into a UIImage

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7096777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档