如何在iOS中检查损坏的PDF? [英] How to check for a corrupted PDF in iOS?

查看:286
本文介绍了如何在iOS中检查损坏的PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PDF文件,我从服务器下载,有时用户上传损坏的PDF,我需要检查我的应用程序是否可以打开这样的文件。

I have a PDF file which I downloaded from a server, sometimes the users uploads a corrupted PDF and I need to check if my application can open such a file or not.

那么我可以使用内置方法来检查PDF损坏吗?如果没有,我可以使用免费的轻量级PDF框架来查看或检查损坏?

So is there a built-in way I could use to check for the PDF corruption ? If not is there a free lightweight PDF framework that I could use to view or checking the corruption ?

注意:目前我在UIWebView上打开PDF文件。

推荐答案

我使用CoreGraphics PDF绘图API找到了解决方案。
感谢您此答案

I've found the solution using the CoreGraphics PDF drawing APIs. Thanks for this answer.

NSString *path = [[NSBundle mainBundle] pathForResource:@"A_Corrupted_PDF" ofType:@"pdf"];
NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];

CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);
CGPDFDocumentRef document = CGPDFDocumentCreateWithProvider(provider);

if (document == nil) {
    NSLog(@"The PDF is corrupted");
}
CGDataProviderRelease(provider);
CGPDFDocumentRelease(document);

这篇关于如何在iOS中检查损坏的PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆