2012-03-01 7 views
1

PDFを生成してNSDocumentDirectoryに保存するアプリケーションを作成しました。ユーザーがファイルを見つけて表示したり、iPhoneで印刷したりするのはとても簡単です。このファイルを見つけて簡単に表示するにはどうすればよいですか?ここでアプリからiPhoneに保存されたPDFにアクセスする方法は?

私はPDFを作成するために使用されるコードは次のとおりです。

 //USE PDFGENERATOR TO CREATE A PDF FILE 
    PDFViewController* pdf = [[PDFViewController alloc] init]; 

    NSString *header = lblTitle.text; 
    NSLog(@"fullQuote=%@", header); 

    NSString *body = [NSString stringWithFormat:@"%@ \n\n - LRH \n %@", lblExcerpt.text, lblDesc2.text]; 
    NSLog(@"fullQuote=%@", body); 

    pageSize = CGSizeMake(612, 792); 
    NSString *fileName = [NSString stringWithFormat:@"%@.pdf", lblTitle.text]; 

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName]; 

    [pdf generatePdf :pdfFileName:header:body:nil]; 

答えて

0

た.pdfを開く方法を示していhere利用できる優れたチュートリアルがあり、アプリケーション内のファイルを.XLS。

これを参照する必要がある主なクラスはQLPreviewControllerです。 iPhone - Opening word and excel file without using UIWebview

このhereはあなたにも、誰かがこのSO質問を参照してくださいしたいと

- (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index 
{ 
    // Break the path into it's components (filename and extension) 
    NSArray *fileComponents = [[arrayOfDocuments objectAtIndex: index] componentsSeparatedByString:@"."]; 

    // Use the filename (index 0) and the extension (index 1) to get path 

    NSString *path = [[NSBundle mainBundle] pathForResource:[fileComponents objectAtIndex:0] ofType:[fileComponents objectAtIndex:1]]; 

return [NSURL fileURLWithPath:path]; 
} 

ために呼び出す必要がありますデータソース方式です。

+0

ありがとう、これは非常に役に立ちます。私はまた、PDFを作成した人のように、ファイルを見つける方法についての簡単な指示をしたいと思うし、今では私のアプリの外部を見たり、ファイルシステム上で別の方法でファイルにアクセスしたりしたいと思っています。それも可能なのでしょうか? – jroyce

関連する問題