Opening a PDF in App Bundle in Safari ? iPhone - iphone

I have a PDF document in my app which I want to allow users to view and email if required.
I would like to open the document in Safari which then should give me access to the forward action in the Safari PDF reader.
How can I open Safari and display the PDF ?
Thank you.

EDIT
this just came to my mind that you won't be able to see the pdf as it is in the sandbox of your app and safari is a different app , so if you want to show it you can use a WebView instead safari... you can use this code instead...
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
NSString *path = [[NSBundle mainBundle] pathForResource:#"document" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
[webView release];

Related

Can’t Display A Microsoft Word.doc document on UIView Controller

I’m using the code below to display pdfs or filename.doc Microsoft Word documents. It works fine when I use a ofType:#:”pdf”, but my code crashes when I use ofType:#:”doc” or ofType:#:”docx”. The Word document is mostly text and a few url links. Any help appreciated.
NSString *path = [[NSBundle mainBundle] pathForResource:#"C9" ofType:#"doc"];
pdfUrl = [NSURL fileURLWithPath:path];}
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
As per your code, it looks like you're already using a UIWebView.
Here is some code I've used in the past.
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView {
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
In viewDidLoad (change webView frame to whatever you need)..
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
[self.view addSubview:webView];
[self loadDocument:#"file.doc" inView:webView];
Take a look at using QLPreviewController to display these document types.
For the crash, are you sure the file exists at the specified location? Check it's actually being copied to the bundle and that there is a file at that path / URL before you use it.

uiwebview is not showing PDF properly as showing in safari

I am having a strange issue. UIwebview is not showing PDF file properly as it shows when I load the PDF file from web URL or in safari browser.
http://www.winsolz.com/temp/2.jpg
I am using the following code to open the PDF from local system.
NSString *pathFOrPDF = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"Page%#", strPDFNumber] ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:pathFOrPDF];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[myWebview loadRequest:request];
[myWebviewLandscape loadRequest:request];
Thanks.
I don't think it would fix your case but I had a pdf showing in safari and not showing in a UIWebView and my problem was that the file extension was not correct. I appended a .pdf at the end of the local file url and started working.
I've noticed that safari check also content types so maybe it is working on safari as you provide a remote url?
this might help.
UIWebView *webView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
webView.backgroundColor = [UIColor redColor];
NSString*fileName= #"About_Downloads";
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:#"pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path isDirectory:NO]];
[webView setScalesPageToFit:YES];
[webView loadRequest:request];
[self.view addSubview:webView]

How to show a PDF page by page using horizontal swipe in iphone?

I would like to add to my app a pdf viewer which can scroll horizontally. Anyone know how to do it? I'm making several attempts but without success. Thanks. Matteo
Use UIWebViewController in landscape orientation and this piece of code can give you an idea about how to display pdfs:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake( 0, 0, 320, 480 )];
NSString *path = [[NSBundle mainBundle] pathForResource:#"about" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
webView.scalesPageToFit = YES;
[self.view addSubview:webView];
[webView release];

Display pdf from the weburl iphone sdk

I am working on one project I want to display the pdf which is on the website, I have the url of the pdf any idea how I can do it.
Also I want to create a thumbnail of the pdf which is on the website.
you could display a pdf in your device.
Passing the url to UIWebView directly.
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 360, 420)];
NSURL *targetURL = [NSURL URLWithString:#"http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIWebView_Class/UIWebView_Class.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
[webView release];

iphone : how can we store pdf file in local and read it?

i want to store pdf file in local and read it . i want to read this pdf same as iphone read data in mkmapview.
means i want to create same as pdf(Acrobat) reader.how can i do this?
you can store the pdf in the application bundle and display it using a uiwebview:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
NSString *path = [[NSBundle mainBundle] pathForResource:#"document" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
[webView release];
to load it from an url you can do something like this:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
NSURL *targetURL = [NSURL URLWithString:#"http://www.mywebsite.com/myPdfFile.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
[webView release];
you can also download your pdf into the documentDirectory during runtime and load it from there.
i think you need this
http://github.com/akisute/iPhonePDF
from here you can find code (api) by that you can genrate pdf in iphone .
and also can do edit it.
Let me know this is what you need ?
You can open the PDF with iBooks or any other app that can read PDF files to store it locally on the Phone.