如何从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".