如何从Caches目录加载PDF?

时间:2012-01-07 22:09:07

标签: objective-c caching pdf show nsdocumentdirectory

我有一个相当简单的问题。如何在Caches目录中打开PDF文件?

我唯一的代码是在应用程序包中打开PDF文件。

myDocumentRef = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL URLWithString:@"Matsedel.pdf"]);
NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"Matsedel.pdf" withExtension:nil];
myDocumentRef = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
myPageRef = CGPDFDocumentGetPage(myDocumentRef, 1);

我认为这很容易做到,但我无法弄清楚。谢谢。

1 个答案:

答案 0 :(得分:1)

你可以尝试类似的东西:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachePath = [paths objectAtIndex:0];
NSURL *fileURL = [NSURL fileURLWithPath:[cachePath stringByAppendingPathComponent:@"Matsedl.pdf"]];