简体   繁体   English

在离线WebApp / Mobile Safari中显示PDF

[英]Display PDF in offline WebApp / Mobile Safari

I'm looking for a solution to display an embedded PDF Document in a WebApp that runs offline on an iPad. 我正在寻找一种在iPad上离线运行的WebApp中显示嵌入式PDF文档的解决方案。 I tried some JS / jQuery Scripts but none of them support the common multitouch gestures (pinch to zoom / swype to switch page). 我尝试了一些JS / jQuery脚本,但它们都不支持常见的多点触控手势(捏缩放以缩放/ swype切换页面)。 They do only show the PDF without any further functionality. 它们仅显示PDF,没有任何其他功能。

PDF.JS isn't a solution as well, because it runs only on firefox browsers. PDF.JS也不是一种解决方案,因为它仅在firefox浏览器上运行。

Can you help me? 你能帮助我吗? Thank you! 谢谢!

this can be done with the UIWebView. 这可以通过UIWebView完成。

If you are trying to display a PDF file residing on a server somewhere, you can simple load it to your web view directly: 如果您尝试显示驻留在某处服务器上的PDF文件,则可以直接将其简单地直接加载到Web视图中:

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];

NSURL *targetURL = [NSURL URLWithString:@"http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIWebView_Class/UIWebView_Class.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];

[self.view addSubview:webView];

Or if you have a PDF file bundled with your application (in this example named "document.pdf"): 或者,如果您的应用程序捆绑了一个PDF文件(在此示例中为“ document.pdf”):

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];

NSString *path = [[NSBundle mainBundle] pathForResource:@"document" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];

[self.view addSubview:webView];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM