0

我正在尝试使用此解决方案将 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 文件转换为图像吗?

非常感谢 !

4

2 回答 2

1

您使用不正确的 API 创建 URL,您需要 URLWithString:

CFURLRef urlRef = (CFURLRef)[NSURL URLWithString:@"http://uat.okitoo.fr/document/document/s595_506cb1811852f/o_specimen-page-seule.pdf"];

您当前使用的 API 用于本地文件系统上文件的 url。

于 2012-10-04T00:12:27.647 回答
0

正如消息所说,您urlRef的可能是nil.

可能是因为你没有提到真正的完整路径而只提到了文件名,并且找不到文件。

如果您的 PDF 是应用程序包中的文件,请使用[[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"]. 如果您在运行时将其下载到沙箱中的某个位置,只需使用下载 PDF 的路径即可。

于 2012-10-03T23:46:07.610 回答