【问题标题】:fetching the 1st page of pdf as UIImage in ipad development在 ipad 开发中获取 pdf 的第一页作为 UIImage
【发布时间】:2011-08-17 17:10:54
【问题描述】:

在 ipad 开发中,有没有办法将 pdf 文件的第一页作为 UIImage? 如果您现在没有确切的解决方案,您能告诉我应该采取哪种方式吗??

我试过这个函数..但是 UIGraphicsGetCurrentContext() 什么也没返回...

+(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;
}

谢谢 鞋子

【问题讨论】:

    标签: iphone ipad pdf uiimageview uiimage


    【解决方案1】:

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

    https://gist.github.com/892868

    此外,这是过去在 SO 上的帖子/答案:

    Rendering a CGPDFPage into a UIImage

    【讨论】:

    • 分类给出了奇怪的链接错误 createPDFDocumentWithName in UIImage+imageWithPdfNamed.o Symbols not found
    • 您是否链接到任何必需的库,例如 CoreGraphics(我猜是必需的库)?
    • 您的问题是否已解决,或者您仍然看到链接错误?我会检查并确保所有必需的库都链接到您的项目中。您是否有机会使用带有嵌套项目的工作区?
    • 嗨,肖恩沃尔,我也在尝试生成相同的缩略图,但根本找不到制作方法,请在stackoverflow.com/questions/8652472/… this 上提出一些建议
    猜你喜欢
    • 2012-06-07
    • 2019-05-02
    • 2023-02-21
    • 1970-01-01
    • 2017-07-19
    • 2011-03-04
    • 1970-01-01
    • 2018-02-27
    • 2011-06-25
    相关资源
    最近更新 更多