我正在尝试使用此解决方案将 pdf 文件转换为图像:
CFURLRef urlRef = (CFURLRef)[NSURL fileURLWithPath:@"http://uat.okitoo.fr/document/document/s595_506cb1811852f/o_specimen-page-seule.pdf"];
CGImageSourceRef src = CGImageSourceCreateWithURL(urlRef, NULL);
NSDictionary* options = [NSDictionary dictionaryWithObject:(id)[NSNumber numberWithInt:500] forKey:(id)kCGImageSourceThumbnailMaxPixelSize];
CGImageRef firstPage = CGImageSourceCreateImageAtIndex(src, 0, (CFDictionaryRef)options);
UIImage* imagePDF = [UIImage imageWithCGImage:firstPage];
CGImageRelease(firstPage);
我的 pdf 文件没问题,但是当我尝试此代码时,图像没有出现,并且我收到以下消息:“: ImageIO: CGImageSourceCreateImageAtIndex 图像源参数为零”。看不懂..
我尝试了其他链接,但遇到了同样的问题..
有什么想法吗? 还有其他方法可以将我的 pdf 文件转换为图像吗?
非常感谢!
最佳答案
您使用了不正确的 API 来创建 URL,您需要 URLWithString:
CFURLRef urlRef = (CFURLRef)[NSURL URLWithString:@"http://uat.okitoo.fr/document/document/s595_506cb1811852f/o_specimen-page-seule.pdf"];
您当前使用的 API 用于获取本地文件系统上文件的 URL。
关于ios - CGImageSourceCreateImageAtIndex 返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12718411/