Question

I use vfr/reader to open PDF files. When I open first PDF file my app opens it correctly but when I open another one, my app opens the first file again.

This is my function to read PDF file

-(void)readIssue:(IssueMath *)issue {

    NSString *filePath = [[issue.contentURL path] stringByAppendingPathComponent:@"Mathematics.pdf"];

    NSLog(@"Read Path 1: %@ ",filePath);

    ReaderDocument *document = [ReaderDocument withDocumentFilePath:filePath password:nil];
    NSLog(@"Read Path 2: %@ ",document.fileURL);

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

    readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;

    [self presentModalViewController:readerViewController animated:YES];
}

And this is NSLog output:

2012-11-02 20:09:31.081 MAGAZINE[314:15203] Read Path 1: /Users/eakmotion/Library/Application Support/iPhone Simulator/5.0/Applications/EC25BC08-E1E7-44B6-9AD8-0A321EEAC8B6/Library/Caches/ISSUE3_2011/Mathematics.pdf 

2012-11-02 20:09:31.109 MAGAZINE[314:15203] Read Path 2: file://localhost/Users/eakmotion/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/EC25BC08-E1E7-44B6-9AD8-0A321EEAC8B6/Library/Caches/ISSUE2_2011/Mathematics.pdf 

I want to read "ISSUE3_2011/Mathematics.pdf" but app still reads first path "ISSUE2_2011/Mathematics.pdf"

Why filePath is still the same?

How can I solve this problem?

Was it helpful?

Solution

Yeah your solution works but if you want to keep track of your all pdf documents (ex. current page no)

You have to give unique names for your local pdf files.. Because it will search for Mathematics.plist file on local device folder to read the current page number..

/Users/eakmotion/Library/Application Support/iPhone Simulator/5.0/Applications/EC25BC08-E1E7-44B6-9AD8-0A321EEAC8B6/Library/Caches/ISSUE3_2011/Mathematics.pdf

file://localhost/Users/eakmotion/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/EC25BC08-E1E7-44B6-9AD8-0A321EEAC8B6/Library/Caches/ISSUE2_2011/Mathematics.pdf

these files are looking for the same Mathematics.plist file in the class ReaderDocument "unarchiveFromFileName" method

NSString *archivePath = [ReaderDocument applicationSupportPath]; // Application's "~/Library/Application Support" path

NSString *archiveName = [[filename stringByDeletingPathExtension] stringByAppendingPathExtension:@"plist"];

try to modify this code section or give your files unique names like Mathematics_ISSUE3_2011.pdf and Mathematics_ISSUE2_2011.pdf

OTHER TIPS

I know this question is quite a few months old, but just in case anyone is experiencing this same issue (as myself), I have found a solution for it.

In the vfr/Reader's source, locate the Sources/ReaderDocument.m file, and look for a function named + (ReaderDocument *)withDocumentFilePath:.

There, comment out the conditional which prevents the document from reloading as shown below.

+ (ReaderDocument *)withDocumentFilePath:(NSString *)filePath password:(NSString *)phrase
{
    ReaderDocument *document = nil; // ReaderDocument object

    document = [ReaderDocument unarchiveFromFileName:filePath password:phrase];

    //if (document == nil) // Unarchive failed so we create a new ReaderDocument object
    //{
    document = [[ReaderDocument alloc] initWithFilePath:filePath password:phrase];
    //}

    return document;
}

This was my quick and dirty approach to get documents to reload. The caveat to this solution is that the pdf reader won't keep track of where you left off in your pdf pages, which in my app, was not of importance.

I was facing the same problem and found following solution:

// Path to first PDF file
NSString *filePath = 
    [[NSBundle mainBundle] pathForResource:@"someBookeName" ofType:@"pdf"];

Just change the file path like shown above. As you can see, now you don't need NSArray * PDF.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top