Display pdf from the weburl iphone sdk - iphone

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

Related

UIWebView not showing properly on iPad

I am building a very simple application for iphone and ipad with a UIWebView which load site, but there is an issue, it is working properly on iphone but on iPad the site moved upward and is even not scrollable.
Following are the screenshots:
iphone:
ipad:
You can see the header section on ipad is not visible, please help me.
here is .m file code
UIWebView *myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,myView.frame.size.width,myView.frame.size.height)];
myWebView.delegate = self;
myWebView.scalesPageToFit = YES;
NSString *urlString = #"http://www.webhousemedia.com/?";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
myWebView.frame = [[UIScreen mainScreen] bounds];
[self.view addSubview:myWebView];
try this..
UIWebView *myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,self.view.bounds.size.width,self.view.bounds.size.height)];

Opening a PDF in App Bundle in Safari ? 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];

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

How to Add a PDF Document to a UIWebView using ASIHTTP

I have the following code in viewDidLoad
NSURL *url = [NSURL URLWithString:URL_TO_DOWNLOAD];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
When this is completed I want to view the URL (PDF) downloaded inside my UIWebView. I create a UIWebView programatically however I can't figure out a way to loadRequest my actual ASIHTTP Request.
you could display a pdf in your device by two way.
first by passing the url to UIWebView directly, in this case you do'nt require to download pdf file
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];
And the second way , you first need to download (As you are doing) then get the path of pdf file from your application bundle,
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
NSString *pdfpath = [[NSBundle mainBundle] pathForResource:#"mypdf" ofType:#"pdf"];
NSURL *pdfURL = [NSURL fileURLWithPath:pdfpath ];
NSURLRequest *pdfRequest = [NSURLRequest requestWithURL:pdfURL ];
[webView loadRequest:pdfRequest];
[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.