views:

78

answers:

1

Hello, I have file test.pdf in my Application Bundle. I run test in iPhone Simulator (iPad) and I cannot get the CGPDFDocumentRef populated. Am I going crazy or what?!?

here is a piece of code from the sample application made especially for this (ViewController class):

- (void)viewDidLoad {
    [super viewDidLoad];
    // below code to show files in app bundle...
 NSString *path = [[NSBundle mainBundle] resourcePath];
 NSFileManager *fm = [NSFileManager defaultManager];
 NSError *error = [[NSError alloc] init];
 NSArray *directoryAndFileNames = [fm contentsOfDirectoryAtPath:path error:&error];

 //just to make sure the file is there : (test.pdf)
 for (NSString *ts in directoryAndFileNames) {
  NSLog(ts);  // NSLog confirms the file is there
 }

 //Function below is supposed to create the CDPDFDocumentRef
 [self updatePageRef]; // try to get the CGPDFDocumentRef
}

-(BOOL)updatePageRef {
 NSLog(@"Updating PAGE");

 NSString *pdfStringURL = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];
 NSURL *pdfURL = [NSURL fileURLWithPath:pdfStringURL];
 NSLog([pdfURL path]); // this is good

 NSLog(@"File Exists = %d", [[NSFileManager defaultManager] fileExistsAtPath:pdfStringURL]); // this gives me 1 (YES)

 pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);    
    //from here on the pdf is nil??????????!!!!!!!!!!!!!

 if (pdf && CGPDFDocumentGetNumberOfPages(pdf) > 0) {
  return YES;
 }

 return NO;
}

Above the pdf is declared in the @interface as CGPDFDocumentRef pdf; I know the PDF file is good, because I have opened it successfully in 'preview'.

Everything compiles and runs without any warnings nor errors.

Help!

A: 

I have found a solution, sorry for asking on first place. The PDF was not good somehow although it was showing perfectly in 'preview'. I have put another pdf, named it 'test.pdf' and all went well.

Cheers!

Sasho