Berk Bozkurt
Berk Bozkurt

Reputation: 1

Unable to create ReaderDocument Vfr-Reader

I searched a lot but can't open PDF with vfr-reader from documents folder.

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];

}

I am sure that filepath is exact the pdf file.

In the example code of reader it opens the pdf from main bundle. But I need to open from resources folder.

Thanks

Upvotes: 0

Views: 1309

Answers (4)

Nathan B.
Nathan B.

Reputation: 2175

I understand this is an old post but none the less I ran into a similar problem as @user1392687 and wanted to share how I resolved the issue (I was loading files from various directories not just the Documents folder).

Problem: Load a series of PDF files out of a directory, populate a table view with filenames and supporting meta data, then upon selecting a cell, open the PDF file using VFR Reader.

Solution: The folder within X-Code is a Folder Reference to enable content updates without having to perform the remove/add cycle of a Group Reference. The function below was used to read all contents - URLs - of a specific folder path then remove all/any simlinks contained within the returned file paths. Prior passing the URL into VRF to load the PDF file [url path] was used for a RFC 1808 (unescaped) path.

+ (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;
}

After populating the table view with the contents of the folder and all supporting metadata, and upon a user touching a row to view the PDF file, the VRF Reader was setup as follows:

- (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];
    }
}

Upvotes: 0

freelancer
freelancer

Reputation: 1658

i facing same issue, may be you also have same one.

if you are not using ARC than just write -fobjc-arc to every pdf reader file in build face. that will solve your problem.

Upvotes: 1

dhaya
dhaya

Reputation: 1522

You should give file name like below code,don't give directly

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

Upvotes: 0

steipete
steipete

Reputation: 7641

You should use [[NSBundle mainBundle] bundlePath] and stringByAppendingPathComponent: instead of hard-coding the string. This is quite horrible and will only ever work on the iOS Simulator.

Upvotes: 0

Related Questions