【发布时间】: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