How to display pdf on iOS(如何在 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 (online) 的自定义 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
方法或 QuickLook framework 使其离线,这意味着每次添加新的 PDF 文章时我都必须发布更新补丁(如果我错了,请纠正我)
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 直接从您的 bundle 中获取 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iOS 上显示 pdf
- URL编码Swift iOS 2022-01-01
- UITextView 内容插图 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01