Reputation: 320
i triad to click on URL which is in PDF file. and PDF file opened in UIWebView, but i cant able to click on URL.
any one tell me how to open URL which is in PDF file.
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)];
NSURL *targetURL = [NSURL URLWithString:@"http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
Upvotes: 1
Views: 845
Reputation: 5064
In you webView deleget method, first of detect the url from PDF and then open in webview or etc. I have used following method to do this, may be its helping you :
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *requestURL = [[ request URL] retain];
if (([[requestURL scheme] isEqualToString: @"http"] || [[requestURL scheme] isEqualToString: @"https"]) && (navigationType == UIWebViewNavigationTypeLinkClicked))
{
// Your method when tap on url found in PDF
}
}
Upvotes: 2
Reputation: 67
If you have a PDF file in Local storage
NSString *html = [NSString stringWithContentsOfFile:path1 encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]bundlePath]]];
If you have Access to file From the Internet
- (void) loadRemotePdf
{
CGRect rect = [[UIScreen mainScreen] bounds];
CGSize screenSize = rect.size;
UIWebView *myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,screenSize.width,screenSize.height)];
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
NSURL *myUrl = [NSURL URLWithString:@"http://www.mysite.com/test.pdf"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myUrl];
[webView loadRequest:myRequest];
[window addSubview: myWebView];
[myWebView release];
}
Upvotes: 0