如何将PDF转换为图像?

时间:2011-05-22 14:31:52

标签: iphone ios uiimageview

是否有将PDF文档(或至少PDF文档的第一页)转换为图像的原生方式?

1 个答案:

答案 0 :(得分:5)

使用ImageIO.framework,您可以执行以下操作:

CGImageSourceRef src = CGImageSourceCreateWithURL(PDF_URL, NULL);
NSDictionary* options = [NSDictionary dictionaryWithObject:(id)[NSNumber numberWithInt:500] forKey:(id)kCGImageSourceThumbnailMaxPixelSize];
CGImageRef firstPage = CGImageSourceCreateImageAtIndex(src, 0, options); // 0 first page of the pdf
CFRelease(src);
UIImage* img = [UIImage imageWithCGImage:firstPage];
CGImageRelease(firstPage);