在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;
}
由于 Shoeb