views:

54

answers:

1

Hi all

I have a pdf file in my iPad application. I want to save that pdf file on iPad so that I can read it out of my application. I am using the following path for save pdf file on iPad:-

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

 NSString *documentsDirectory = [paths objectAtIndex:0];

 NSString *fileBPath = [documentsDirectory stringByAppendingPathComponent:@"tmp.pdf"];

But I am not able to find this pdf file on my iPad. Can anyone suggest me how can I find it ?
Is file path wrong? then suggest me the file path for saving the pdf file ?

Thanks in Advance

+1  A: 

1) See this SO question/answer regarding creation of a pdf from a UIView

2) If you already have the pdf file as an NSData object, you can save that to a file in your documents directory using

[NSData writeToFile:fileBPath atomically:YES];

3) On the other hand, if the PDF file is part of your application bundle (ie included with the app at compile time) it won't be in the documents directory.

Take a look at the documentation for [NSBundle mainBundle] -- that is where your PDF will be.

TomH
Deepika
@Deepika I've updated my answer above. You have a few different options depending on how/if you have created the pdf
TomH
Pdf is successfully created on iPad....but I am not able to find the icon of that file on ipad so that I can read it directly.
Deepika
What do you mean by 'not able to find the icon'?
TomH
I mean to say that how can I open that file outside the application ?
Deepika
Good question. I don't know that you will be able to open the pdf from outside of your application. You *may* however be able to open the pdf with iBooks from within your app. iBooks registers itms-books: and itms-bookss: URL schemes so you *might* be able to open the pdf by constructing a URL with one of those schemas.
TomH
Here's another resource that may be helpful: UIDocumentInteractionController. http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIDocumentInteractionController_class/Reference/Reference.html
TomH