在iOS应用中显示.pdf,而无需从互联网上下载它 [英] Display a .pdf in an iOS app without downloading it from the internet

查看:202
本文介绍了在iOS应用中显示.pdf,而无需从互联网上下载它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找将.pdf文件与我的应用程序打包在一起的方法,以便用户可以在该应用程序的选项卡式UIViews中查看它.我读过的大多数文章都解释了如何显示必须首先从Internet下载的.pdf.我的问题是:如何访问该应用程序随附的.pdf并将其显示在UI(Web)View(无需Internet访问/下载)上?

I'm looking to package a .pdf file with my app so that users can view it on one of the app's tabbed UIViews. Most of the posts I've read explain how to display a .pdf that must be downloaded first from the internet. My question is: how do you access a .pdf that is packaged with the app and display it on a UI(Web)View (with no internet access/download required)?

:此代码段是关键(将"ReadFile.pdf"添加到项目中的是.pdf):

This snippet was the key (where "ReadFile.pdf" was .pdf added to the project):

NSString * urlAddress = [[NSBundle mainBundle] pathForResource:@"ReadFile" ofType:@"pdf"];

NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"ReadFile" ofType:@"pdf"];

推荐答案

这是您应该做的:

– (void) displayLocalPdfInWebView
{
    CGRect rect = [[UIScreen mainScreen] bounds];
    CGSize screenSize = rect.size;

    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,screenSize.width,screenSize.height)];
    webView.autoresizesSubviews = YES;
    webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);

    NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"JaapSahib-Gurmukhi" ofType:@"pdf"];

    NSURL *url = [NSURL fileURLWithPath:urlAddress];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];

    [webView loadRequest:urlRequest];

    [window addSubview:webView];
    [webView release];

}

来源: http://www.developerfeed.com /how-display-local-pdf-file-ios-uiwebview/

这实际上将是:

  1. 创建一个CGRect来设置屏幕边界
  2. 允许自动调整大小
  3. 将UIWebView设置为资源
  4. 将文件加载到UIWebView

评论,告诉我进展如何!

Comment, and tell me how it goes!

这篇关于在iOS应用中显示.pdf,而无需从互联网上下载它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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