2

I need to display pdf documents within my iPad app, I've seen people suggesting loading it within a webview.

I want to know if this is the best\recommended way to display a pdf?

kd02
  • 422
  • 5
  • 14

2 Answers2

4

Using a QuickLook.framework you can easly load pdf and disply i just add following easy step for load pdf using QuickLook.framework

  • Add QuickLook.framework and import in to your class and set it's DataSource in to .h class <QLPreviewControllerDataSource>

Use following method:

-(NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
    return 1;
}

- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    return [NSURL fileURLWithPath:self.pdfFilePath]; // here is self.pdfFilePath its a path of you pdf
}

and for load set Button Action:

-(IBAction)LoadPdf
{
        QLPreviewController* preview = [[[QLPreviewController alloc] init] autorelease];
        preview.dataSource = self;
        [self presentModalViewController:preview animated:YES];
}
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
  • Found that viewing a pdf is actually rather simple, tried the above code and worked well. Do u my data sometimes being a url to the relevant pdf I was forced to go the webview route but would have preferred to use QLPreviewController – kd02 Sep 10 '14 at 08:11
1

Two easiest way to that

  1. UIWebView
  2. QLPreviewController
Sunny Shah
  • 12,990
  • 9
  • 50
  • 86
  • Apple will stop accepting submissions of app updates that use UIWebView APIs starting from December 2020. See https://developer.apple.com/documentation/uikit/uiwebview for more information. – Panayot Apr 22 '20 at 11:43