如何在iOS上显示pdf [英] How to display pdf on iOS

查看:360
本文介绍了如何在iOS上显示pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何方法可以离线构建xcode iOS,以便我们可以显示本地文件中的pdf文件.

I want to know if there is any way for a offline build for xcode iOS such that we can display pdf file from local file.

我现在使用的方法是通过UIWebView来显示包含PDF URL(在线)的自定义HTML,但如果可能的话,我想制作一个离线版本.

The method I'm using now is via UIWebView to display a custom HTML which contain the PDF URL (online) , but I want to make an offline version if possible.

但是从在线研究来看,在我看来,显示PDF的唯一方法是通过UIWebView,如果确实如此,是否有可能从本地资源中提取文件(例如,将文件添加到我的xcode资源文件夹中),而不是而不是使用PDF URL.

But from online research, it seems to me the only way to display PDF is via UIWebView, if that is really the case, is it possible to pull the file from local resource (e.g. add files to my xcode resource folder) rather than using the PDF URL.

主题外: 哪个是更好的选择?要提取本地文件还是将在线URL用于PDF文件?

OFF-TOPIC: Which would be a better choice? To pull local file or to use the online URL for PDF file?

由于UIWebView需要连接,因此仅拉动在线URL似乎是一个更好的选择,因为它将是最新的和更新的.

As UIWebView require connection, it would seem to be a better choice to just pull the online URL as it will be the most current and updated.

非常感谢您提供反馈.

如果我使用UIDocumentInteractionController方法或

quick question, if I use the UIDocumentInteractionController method or the QuickLook framework to make it offline, this would mean I have to release update patch each time there is new PDF article added in (correct me if I'm wrong)

考虑到这一点,我当场就我自己的问题提出了反驳(对不起,如果您觉得您在浪费我的时间,请问.>.,我是一个喜欢的人质疑可能性和解决问题可能采取的不同方法) 为了节省不断更新的时间并提供一个实时的基础解决方案,即使用UIWebView(我知道这与我的SO线程的目的相矛盾),因为该项目基于在线网站(获取我的内容)以及从那里获得的资源),如果我要为文章部分加载其网站,我是否会大胆地说,通过添加NSString变量,我可以将NSRange函数与UIWebView一起添加到viewDidLoad中,以便URL将永远不会离开新闻部分和PDF URL.例如使用if和NSRange函数的组合来反检查该URL仅包含新闻部分和PDF URL)

Taking this point into consideration, I've come up with a counter-argument to my own question on the spot (Sorry if any of you feel you are wasting time on me >.<, I am a person who like to question possibilities and the different approach one could take to solve a problem) In the event to save time from the constant updating and providing a real time base solution, which is to use UIWebView (I know this is contradicting my purpose of this SO thread), as this proj is base on a online website (getting my content and sources from there), if I were to load their website for the article section, would it be bold of me to say that by adding a NSString variable, I can add in the NSRange function to the viewDidLoad together with the UIWebView such that the URL will never leave the news section and PDF URL. e.g. using combination of if and NSRange function to counter check that the URL only contain the news section and PDF URL)

我在使用NSRange函数进行计算器运算之前曾做过一次,所以我认为现在是将其用于此框架应用程序的好时机.

I did once before a NSRange function for point on calculator so I thought it would be a good time to put it in use for this framework app.

P.S-这个应用程序是一个组织基础项目,我是一名实习生,为他们提供基础框架.

P.S - This app is a organization base project and I'm a intern providing them with the base skeleton framework.

推荐答案

您可以使用UIWebView直接从包中获取PDF,而无需调用在线Web服务.

You can use a UIWebView to get the PDF from your bundle directly, no need to call an online web service.

本地文件:

NSString *html = [NSString stringWithContentsOfFile:path1 encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]bundlePath]]];

远程文件:

- (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];
            
}

这篇关于如何在iOS上显示pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆