views:

184

answers:

0

Hi all,

I am using the 'Leaves' framework to add a page turn effect to my app. It displays PDF's using quartz and this works fine if you are loading a PDF from the main bundle. Here is the working code:

CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), 
CFSTR("SampleIssue.pdf"), NULL, NULL);
pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
NSLog(@"PDF: %@", pdf);
CFRelease(pdfURL);

I want to load a PDF from the documents directory though. Here is my code (which doesn't work):

// Get Documents Directory
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectoryPath = [searchPaths objectAtIndex:0]; 
NSString *tempPath = [documentsDirectoryPath stringByAppendingPathComponent:[appDelegate.issueToLoad stringByAppendingPathExtension:@"pdf"]];
NSString *path = [tempPath stringByReplacingOccurrencesOfString:@"localhost/" withString:@""];
NSLog(@"PATH: %@", path);

//Display PDF
CFURLRef pdfURL = CFURLCreateWithFileSystemPath (NULL, (CFStringRef)path, kCFURLPOSIXPathStyle, FALSE);
NSLog(@"PDF URL: %@", pdfURL);
pdf = CGPDFDocumentCreateWithURL(pdfURL);
NSLog(@"PDF: %@", pdf);

My code gets the correct link to the file. However the final NSLog shows the 'pdf' is NULL. This is obviously a problem and the PDF doesn't load. Can anybody see any obvious problems with my code? Or do you know how I can accomplish this?

Thanks!