iOS vfr阅读器框架无法使用下载的pdf [英] iOS vfr reader framework cannot use downloaded pdf

查看:101
本文介绍了iOS vfr阅读器框架无法使用下载的pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了vfr阅读器框架,同时研究了一些更好的替代方法来在应用程序中显示pdf.就我而言,我需要下载pdf文件;它尚未包含在应用程序捆绑包中.可以将vfr框架与嵌入式pdf一起使用很容易,但是到目前为止,我对使它与我将其写入文件的下载数据一起使用,然后使用其路径初始化ReaderDocument感到困惑.我能够将同一文件加载到UIWebView中没问题,所以我不认为这是数据.这是代码:

I found the vfr reader framework while looking into some better alternatives for displaying pdf in an app. In my context, I need to download a pdf; it's not included in the app bundle already. It was easy to use the vfr framework with an embedded pdf, but I've been stumped so far with getting it working with downloaded data that I write to a file, then init a ReaderDocument with it's path. I'm able to load the same file into a UIWebView no problem, so I don't believe it's the data. Here's the code:

NSString *fullPathToPDF = [[[self appDelegate] urlForFileUnderRecursiveDocWithName:self.pdfName andOptionallyStartingAtDirectory:[[self appDelegate] pathURLForImagesDirectory]] path];
        ReaderDocument *pdfDoc = [ReaderDocument withDocumentFilePath:fullPathToPDF password:nil];

生成的pdfDoc将为null,或者将其传递给上述完整路径时,将因ReaderDocument的第229行的断言而崩溃

The resulting pdfDoc will either be null, or, when passing it the full path like above, will crash with an assertion from line 229 of ReaderDocument

NSAssert(NO, @"CGPDFDocumentRef == NULL");

因为(我做一个合理的假设)这一行(217;同一个班级):

because (I'm making a reasonable assumption) this line (217; same class):

CGPDFDocumentRef thePDFDocRef = CGPDFDocumentCreateX(docURLRef, _password);

无法创建CGPDFDocumentRef.前面我提到过将完整路径传递给文件名与将文件名称传递给它之间是有区别的,这是因为在查看代码时,ReaderDocument类似乎对希望在哪里找到文件进行了一些假设.无论我将文件保存到何处,或传递给... withDocumentFilePath方法的内容,我都无法使其正常运行.

fails to create the CGPDFDocumentRef. I previously mentioned a distinction between passing it the full path vs just passing it the file name, and that's because in looking at the code, the ReaderDocument class appears to make some assumptions about where it expects to find the files. I haven't been able to get it working no matter where I save the file to, or what I pass into it's ...withDocumentFilePath method.

重申一下,我可以使用完全相同的文件并在UIWebView中打开它没有问题.

To reiterate, I'm able to use the exact same file and open it in a UIWebView no problem.

那么,有人遇到同样的问题,或者能够成功完成我正在尝试的事情吗?谢谢.

So, anybody having this same issue, or, able to do what I'm attempting successfully? Thanks.

推荐答案

很抱歉回答得这么晚.我本人只是遇到了这个问题,以为我会传承我的智慧.

Sorry to answer this so late. I just came across this problem myself so thought I'd pass along my wisdom.

我的猜测是您正在将PDF下载到临时目录中.该框架在NSDocumentDirectory中查找文件.因此,当您保存下载的文件时,只需保存到以下路径:

My guess is you are downloading the PDF to the temporary directory. This framework is looking for the file in the NSDocumentDirectory. So when you go to save the downloaded file just save to a path like this:

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

执行此操作后,它将正确加载.

Once you do that it will load correctly.

p.s如果最终我修改了ReaderDocument以允许有一个临时目录,我将在此处发布编辑内容.

p.s If I end up modifying ReaderDocument to allow for a temporary directory I'll post the edits here.

这篇关于iOS vfr阅读器框架无法使用下载的pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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