如何从文档目录加载PDF? [英] How to load PDFs from Documents Directory?

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

问题描述

我可以使用此代码从Resources文件夹加载pdf文件列表(所有pdf文件)。

I can load list of pdf files(all pdf files) from Resources folder, using this code.

 NSArray *pdfs = [[NSBundle mainBundle] pathsForResourcesOfType:@"pdf" inDirectory:nil];

但我找不到从Documents Directory加载pdf文件列表的方法。以下代码行可以一次只加载一个 pdf。

But I couldn't find a method to load list of pdf files from Documents Directory. The following line of code can only load one pdf at a time.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *file = [documentsDirectory stringByAppendingPathComponent:@"test.pdf"];
NSURL *urlPdf = [NSURL fileURLWithPath: file];

如何从文档目录加载所有pdf文件

你能给我一个代码示例吗?

Can you please give me a code example.

推荐答案

我能够使用以下代码解决我的问题:)

I was able to solve my issue using this line of code :)

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSArray *pdfs = [[NSBundle bundleWithPath:[paths objectAtIndex:0]] pathsForResourcesOfType:@"pdf" inDirectory:nil];

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

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