2012-05-01 80 views
1

我遇到了一个奇怪的问题。 UIwebview未正确显示PDF文件,因为它显示的是从网址或Safari浏览器加载PDF文件时显示的文件。uiwebview在Safari浏览器中显示不正确的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]; 

谢谢。

+0

我不知道这是否会帮助,但你可以尝试设置Web视图的'scalesPageToFit'属性,看看是否能调整大小。 –

+0

我已经这样做了。 –

回答

1

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

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] 

相关问题