我三合会点击PDF文件中的URL。和UI文件中打开的PDF文件,但我无法点击URL。
任何人都告诉我如何打开PDF文件中的URL。
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];
答案 0 :(得分:2)
在你的webView委托方法中,首先从PDF中检测网址,然后在webview等中打开。我使用了以下方法来做到这一点,可能会帮助你:
- (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
}
}
答案 1 :(得分:0)
如果您在本地存储中有PDF文件
NSString *html = [NSString stringWithContentsOfFile:path1 encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]bundlePath]]];
如果您可以从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];
}