1

test.pdfアプリケーション バンドルにファイルがあります。iPhone Simulator (iPad) でテストを実行しましたが、CGPDFDocumentRef を入力できません。私は気が狂っているのですか、それとも何ですか?!?

これは、このために特別に作成されたサンプル アプリケーション (ViewController クラス) のコードの一部です。

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

上記は 、「プレビュー」で正常に開いたため、PDFファイルが適切であることを知っているためpdf、@interfaceで宣言されています。CGPDFDocumentRef pdf;

すべてが警告やエラーなしでコンパイルおよび実行されます。

ヘルプ!

4

1 に答える 1

1

解決策を見つけました。最初に質問して申し訳ありません。「プレビュー」では完全に表示されていましたが、PDFはどういうわけかうまくいきませんでした。「test.pdf」という名前の別のpdfを配置しましたが、すべてうまくいきました。

乾杯!

于 2010-08-28T00:05:30.157 に答える