uiwebview没有正确显示PDF在safari中显示

时间:2012-05-01 13:30:15

标签: iphone ios uiwebview

我有一个奇怪的问题。当我从网址或Safari浏览器加载PDF文件时,UIwebview没有正确显示PDF文件。

http://www.winsolz.com/temp/2.jpg

我使用以下代码从本地系统打开PDF。

NSString *pathFOrPDF = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Page%@", strPDFNumber] ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:pathFOrPDF];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[myWebview loadRequest:request];      
[myWebviewLandscape loadRequest:request]; 

感谢。

2 个答案:

答案 0 :(得分:1)

我不认为这会解决你的情况,但我在Safari中显示的pdf并没有在UIWebView中显示,我的问题是文件扩展名不正确。我在本地文件URL的末尾添加了.pdf并开始工作。 我已经注意到safari检查也是内容类型所以也许它正在使用safari,因为你提供了一个远程URL?

答案 1 :(得分:0)

这可能有所帮助。

UIWebView *webView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
webView.backgroundColor = [UIColor redColor];
NSString*fileName= @"About_Downloads";
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path     isDirectory:NO]];
[webView setScalesPageToFit:YES];
[webView loadRequest:request];
[self.view addSubview:webView]  

相关问题