开发者

How do I convert a PDF to an image? [duplicate]

开发者 https://www.devze.com 2023-03-07 10:12 出处:网络
This question already has answers here: High quality UIImage from PDF 开发者_JS百科 (7 answers) Closed 6 years ago.
This question already has answers here: High quality UIImage from PDF 开发者_JS百科 (7 answers) Closed 6 years ago.

Is there a native way to convert a PDF document (or atleast the first page of a PDF document) into an image?


Using ImageIO.framework you can do something like this :

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消