PDA

View Full Version : uiwebview to uiimage question




medasmx
Jan 8, 2011, 07:02 AM
- (void)viewDidLoad {

NSString*path=[[NSBundle mainBundle]pathForResource:@"sample2" ofType:@"pdf"];
//Create a URL object.
NSURL *url = [NSURL fileURLWithPath:path];

//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

//Load the request in the UIWebView.
[webView loadRequest:requestObj];

UIGraphicsBeginImageContext(webView.bounds.size);
[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage*someImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

self.myImageView.image=someImage;
}


I created a view-based application, where in the view the screen is split between a webView object and a imageView object in the IB. The pdf shows up fine in the webView, but nothing appears in the imageView. Any ideas? Thanks.



robbieduncan
Jan 8, 2011, 07:26 AM
Is loadRequest synchronous? What will happen if it is not?

medasmx
Jan 8, 2011, 02:14 PM
I solved the problem using quartz and the code below. The sample code (from apple) "QuartzDemo" was what I used to generate the PDF. Seems simpler than using a webview anyway.


CGContextSelectFont(context, "Helvetica", 36, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
const char*text="hello there";
CGContextShowTextAtPoint(context, 100, 100, text, strlen(text));