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.
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 ?
Note: Currently I am opening PDF files on a UIWebView.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With