Instead of loading a PDF from the resources folder I would like to load it from the documents directory. I have been trying to do this for days but the CGPDFDocumentRef keeps returning NULL. Here is my code:
// 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(finalURL);
NSLog(@"PDF: %@", pdf);
The file path is correct and I have checked the simulator documents directory and the file is definitely there. When I run the app the last NSLog says (NULL) and a blank white page PDF is displayed. Any ideas what is wrong? Thanks!