2013-01-10 42 views
0

我搜索了很多,但无法使用vfr-reader从文档文件夹打开PDF。无法创建ReaderDocument Vfr-Reader

NSString *filePath = @"/Users/***/Library/Application Support/iPhone Simulator/5.0/Applications/F2B7E9DE-9996-4F05-BC81-2A2889B4F504/Documents/Number1.pdf"; 
ReaderDocument *document = [ReaderDocument withDocumentFilePath:filePath password:password]; 

if (document != nil) 
{// document comes nil here 

    ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document]; 
    readerViewController.delegate = self; // Set the ReaderViewController delegate to self 
    [self.navigationController pushViewController:readerViewController animated:YES]; 

} 

我相信filepath是完全的pdf文件。

在阅读器的示例代码中,它从主包打开pdf。但我需要从资源文件夹打开。

感谢

+1

你能解决这个问题吗?我有同样的问题;无法使用未包含在主包中的文件获取ReaderDocument。就我而言,我正在下载它,然后将它写入Documents目录; ReaderDocument init始终失败。 – wkhatch

回答

0

您应该使用[[NSBundle mainBundle] bundlePath]stringByAppendingPathComponent:而不是硬编码的字符串。这是非常可怕的,只能在iOS模拟器上运行。

0

你应该给像下面的代码文件名,不给直接

NSArray *pathss = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsPaths = [pathss objectAtIndex:0]; 
    NSString *filePaths = [documentsPaths stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",fileName]]; 
1

我面临着同样的问题,可能你也有同样的一个。

如果您没有使用ARC,而只是将-fobjc-arc写入构建面中的每个pdf阅读器文件。这将解决您的问题。

+0

这解决了我的问题,谢谢 –

0

我明白这是一个旧的帖子,但我遇到类似的问题,作为@ user1392687,并希望分享我是如何解决问题的(我从各种目录加载文件,而不仅仅是文档文件夹)。

问题:从一个目录中加载一系列PDF文件,用文件名填充一个表格视图并支持元数据,然后在选择一个单元格后,使用VFR阅读器打开PDF文件。

解决方案:X代码中的文件夹是一个文件夹引用,用于启用内容更新,而无需执行组引用的删除/添加循环。下面的函数用于读取特定文件夹路径的所有内容(URL),然后删除返回的文件路径中包含的所有/任何simlink。事先将URL传递到VRF中以加载PDF文件[url path]用于RFC 1808(未转义)路径。

+ (NSArray *)enumerateContentsOfFolderWithPath:(NSURL *)aFolderPath 
{ 
    NSError *error = nil; 
    NSArray *contentProperties = @[NSURLIsDirectoryKey, 
            NSURLIsReadableKey, 
            NSURLCreationDateKey, 
            NSURLContentAccessDateKey, 
            NSURLContentModificationDateKey]; 

    NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:aFolderPath 
            includingPropertiesForKeys:contentProperties 
                 options:NSDirectoryEnumerationSkipsHiddenFiles 
                 error:&error]; 
    if (error != nil) 
     DLog(@"Content enumeration error: %@", error); 

    NSMutableArray *pdfURLs = [NSMutableArray array]; 

    for (NSURL *item in contents) 
    { 
     NSURL *fileURL = [NSURL fileURLWithPath: [item path]]; 
     NSURL *noSimlink = [fileURL URLByResolvingSymlinksInPath]; 
     [pdfURLs addObject: noSimlink]; 
    } 
    return pdfURLs; 
} 

填充与文件夹的内容,以及所有支持元数据表视图后,并在触摸一行查看PDF文件的用户,在VRF阅读器是设置如下:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Other setup code... 

    NSURL *item = [pdfURLs objectAtIndex:(NSUInteger) indexPath.row]; 
    [self presentPdfViewerForItem: item]; 
} 

- (void)presentPdfViewerForItem:(NSURL *)aItem 
{ 
    NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files) 
    NSString *filePath = [aItem path]; 
    ReaderDocument *document = [ReaderDocument withDocumentFilePath: filePath password:phrase]; 

    if (document != nil) // Must have a valid ReaderDocument object in order to proceed 
    { 
     ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document]; 
     readerViewController.delegate = self; 
     readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
     readerViewController.modalPresentationStyle = UIModalPresentationFullScreen; 
     [self presentViewController:readerViewController animated:YES completion:nil]; 
    } 
}