如何从iPhone的文档目录中读取pdf文件? [英] How to read pdf file from document directory in iPhone?

查看:362
本文介绍了如何从iPhone的文档目录中读取pdf文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我在iPhone应用程序中工作,我在资源文件夹(本地pdf文件)中有一个pdf文件然后我成功读取了pdf文件(paper.pdf),下面我提到了阅读本地pdf文件供您参考。

Currently i am working in iPhone application, i have an pdf file in resource folder (Local pdf file) then i read that pdf file (paper.pdf) successfully, below i have mentioned read local pdf file for your reference.

示例:

CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("paper.pdf"), NULL, NULL);
pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
CFRelease(pdfURL);

然后我试图在NSDocument目录中存储pdf文件(来自URL),成功存储。

Then i have tried to store pdf file (from URL) in NSDocument directory, stored successfully.

NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.msy.com.au/Parts/PARTS.pdf"]];

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
 NSString *documentsDirectory = [paths objectAtIndex:0]; 
 NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"myPDF11.pdf"];
 [pdfData writeToFile:filePath atomically:YES];

然后我尝试读取该pdf文件(来自NSDocument目录)但我不知道,请帮助我。

Then i tried read that pdf file (from NSDocument directory) but i didn't know that, please help me.

提前致谢

推荐答案

尝试使用此功能:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"myPDF11.pdf"];

NSURL *pdfUrl = [NSURL fileURLWithPath:filePath];
pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
CFRelease(pdfURL);

来自 NSURL reference


NSURL课程与其核心基金会同行CFURLRef免费搭桥。有关免费电话桥接的更多信息,请参阅免费电话桥接。

The NSURL class is toll-free bridged with its Core Foundation counterpart, CFURLRef. For more information on toll-free bridging, see "Toll-Free Bridging".

这篇关于如何从iPhone的文档目录中读取pdf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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