Trying to create thumb pictures of documents that has been opened in my app with openurl
.
My app can open and save .doc .xls and .pdf file, but when I try to save the screenshot it can correctly save the .doc content, for pdf and xls it only saves a blank white picture.
here are some sample documents I am testing:
Here is my code:
-(void)webViewDidFinishLoad:(UIWebView *)webViewCapture
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSLog(@"webViewDidFinishLoad");
NSLog(@"webview %@",webView);
NSLog(@"webViewCapture %@",webViewCapture);
UIGraphicsBeginImageContext(webView.bounds.size);
[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Convert UIImage to JPEG
NSData *imgData = UIImageJPEGRepresentation(viewImage, 1);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePathLocal = [documentsDirectory stringByAppendingPathComponent:@"Inbox"];
NSArray *partialDates =[self.imageFilename componentsSeparatedByString:@"."];//split string where - chars are found
NSString* fileDescription= [partialDates objectAtIndex: 0];
//creatre unique name for image _AKIAIVLFQKM11111
NSString *uniqueFileName=[NSString stringWithFormat:@"%@_AKIAIVLFQKM11111_%@.jpeg",fileDescription,[partialDates objectAtIndex: 1]];
NSString *finalFileName= [filePathLocal stringByAppendingPathComponent:uniqueFileName];
NSError *error = nil;
if ([imgData writeToFile:finalFileName options:NSDataWritingAtomic error:&error]) {
// file saved
} else {
// error writing file
NSLog(@"Unable to write PDF to %@. Error: %@", finalFileName, error);
}
}
NSLOG:
webViewDidFinishLoad
webview <UIWebView: 0xaa79070; frame = (0 44; 768 960); autoresize = W+H; layer = <CALayer: 0xaa51000>>
webViewCapture <UIWebView: 0xaa79070; frame = (0 44; 768 960); autoresize = W+H; layer = <CALayer: 0xaa51000>>
Why I cant save real content for other types of documents with above code?