uiwebview to uiimage question

Discussion in 'iOS Programming' started by medasmx, Jan 8, 2011.

  1. macrumors member

    Joined:
    Nov 9, 2008
    #1
    Code:
     
    - (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.
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Is loadRequest synchronous? What will happen if it is not?
     
  3. thread starter macrumors member

    Joined:
    Nov 9, 2008
    #3
    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.

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

Share This Page