uiwebview to uiimage question

Discussion in 'iPhone/iPad Programming' started by medasmx, Jan 8, 2011.

  1. macrumors member

    - (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];
    	[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
    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.
  2. Moderator


    Staff Member

    Is loadRequest synchronous? What will happen if it is not?
  3. macrumors member

    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));

Share This Page