3

How can I open a PDF file that was stored in my iPad/iPhone, using my own application?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Monish Kumar
  • 2,788
  • 4
  • 38
  • 54

3 Answers3

6

You can use UIwebview to load it. It is very simple. If you want more flexibility you should use Quartz framework classes.

EDIT:

To view downloaded PDF, you can provide open-in functionality in your app. This is how you add "open-in" to your app.

Look here for complete tutorial.

Community
  • 1
  • 1
Vignesh
  • 10,205
  • 2
  • 35
  • 73
2

There is a good tutorial available here which demonstrates how to open .pdf, .xls files in your application.

The main class you have to refer for this is QLPreviewController. here

This is the Datasource Method you would have to call for that

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

Also someone would like to refer this SO question :iPhone - Opening word and excel file without using UIWebview.

Community
  • 1
  • 1
rohan-patel
  • 5,772
  • 5
  • 45
  • 68
  • Is this opens the pdf files which are not in my app's bundle but it was in ipad? – Monish Kumar Mar 13 '12 at 08:51
  • @anonymous, now you are answering even after getting upset from Monish... Dear 'anonymous', this is a community and you should be more polite with your words. Everyone comes here to learn and share their knowledge.. – Saurabh Passolia Mar 13 '12 at 08:57
  • @samfisher : Yes mate..I totally agree that we have to be polite. But I answered for the sake of this community. This answer is for those people who really care to search for a solution and by chance they click here they do not go without getting an answer.. – rohan-patel Mar 13 '12 at 09:52
0

You can use Core Graphics for this task. Look at PDFView sample from apple resources

Ilya Ilin
  • 2,283
  • 21
  • 27