从文档目录加载PDF - iPhone [英] Load PDF from documents directory - iPhone

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

问题描述

我没有从资源文件夹中加载PDF,而是希望
从文档目录中加载它。我一直试图做这个
几天,但CGPDFDocumentRef一直保持返回NULL。这是我的
代码:

Instead of loading a PDF from the resources folder I would like to load it from the documents directory. I have been trying to do this for days but the CGPDFDocumentRef keeps returning NULL. Here is my code:

                // Get Documents Directory 
                NSArray *searchPaths = 
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
NSUserDomainMask, YES); 
                NSString *documentsDirectoryPath = [searchPaths objectAtIndex:0]; 
                NSString *tempPath = [documentsDirectoryPath 
stringByAppendingPathComponent:[appDelegate.issueToLoad 
stringByAppendingPathExtension:@"pdf"]]; 
                NSString *path = [tempPath 
stringByReplacingOccurrencesOfString:@"localhost/" withString:@""]; 
                NSLog(@"PATH: %@", path); 
                //Display PDF 
                CFURLRef pdfURL = CFURLCreateWithFileSystemPath (NULL, 
(CFStringRef)path, kCFURLPOSIXPathStyle, FALSE); 
                NSLog(@"PDF URL: %@", pdfURL); 
                pdf = CGPDFDocumentCreateWithURL(finalURL); 
                NSLog(@"PDF: %@", pdf); 

文件路径是正确的,我检查了模拟器文件
目录,文件是绝对有。当我运行应用程序时,
最后一个NSLog说(NULL)并显示一个空白页面PDF。
任何想法有什么不对?
谢谢!

The file path is correct and I have checked the simulator documents directory and the file is definitely there. When I run the app the last NSLog says (NULL) and a blank white page PDF is displayed. Any ideas what is wrong? Thanks!

推荐答案

显而易见的答案是在DocumentCreate函数中使用pdfURL。 finalURL无处不在,它甚至不明显是什么。

The obvious answer would be to use the pdfURL in der DocumentCreate function. finalURL comes out of nowhere and it's not apparent what it's even there for.

pdf = CGPDFDocumentCreateWithURL(pdfURL);

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

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