2013-01-10 40 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]; 
    } 
}