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

Iphone 在ipad开发中获取pdf的第一页作为UIImage,iphone,ipad,pdf,uiimageview,uiimage,Iphone,Ipad,Pdf,Uiimageview,Uiimage,在ipad开发中,有没有办法将pdf文件的第一页作为UIImage获取??? 如果你现在没有确切的解决办法,你能告诉我应该走哪条路吗 我尝试了此函数..但UIGraphicsGetCurrentContext()不返回任何内容 +(UIImage*) imageFromPDF:(CGPDFDocumentRef)pdf withPageNumber:(NSUInteger)pageNumber withScale:(CGFloat)scale { //if(pageNumber >

在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;
}
+(UIImage*)imageFromPDF:(CGPDFDocumentRef)带页码的pdf:(NSUInteger)带刻度的页码:(CGFloat)刻度
{
//如果(页码>0&&pageNumber
谢谢
Shoeb

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

此外,以下是过去的帖子/答案:


该分类给出了奇怪的链接错误createPDFDocumentWithName in UIImage+imageWithPdfNamed。o未找到符号您是否针对任何必需的库(如CoreGraphics)进行链接(我猜是在必需的库上)?您是否解决了问题,或者您仍然看到链接错误?我会仔细检查并确保所有必需的库都链接到您的项目中。你是否有可能使用嵌套项目的工作区?嗨,shawnwall,我也在尝试相同的缩略图生成,但根本没有找到如何生成。请给出一些建议