How to Read PDF documents from sever using webview? - iphone

I have some PDF books over Server,Here is my code to Read these books from sever.
self.webView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
self.webView.backgroundColor = [UIColor whiteColor];
self.webView.scalesPageToFit = YES;
self.webView.delegate = self;
[self.view addSubview:self.webView];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"url.pdf"]]];
Using this code nothing appear in webview,but when i add the same book in my resourse folder then its works.Can any one help me how can i fix it using above url ?thanx

Just change your last line to this :
NSString *urlString = #"url.pdf";
NSString *encodedUrl = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *targetURL = [NSURL URLWithString:encodedUrl];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
self.webView loadRequest:request];
The link of pdf file you provided contains file with thousands of pages,so it might take time to load.

Related

Instagram login in iPhone sdk

I am implementing instagram in my application.I am following the code from "https://github.com/crino/instagram-ios-sdk"
This code is working fine and instagram call is made in the app delegate.
"self.instagram = [[Instagram alloc] initWithClientId:APP_ID delegate:nil]"
But I want to use this in the view controller not in the app delegate.
When I try to do that it is not calling the "-(void)authorize:(NSArray *)scopes" method and so Instagram is not loading.
Please suggest me some way out for this.
Found the solution. My code:
self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
self.webView.delegate = self;
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString: [NSString stringWithFormat:kAuthenticationEndpoint, kClientId, kRedirectUrl]]];
[self.webView loadRequest:request];
[self.view addSubview:self.webView];
Where: kAuthenticationEndpoint=#"https://instagram.com/oauth/authorize/?client_id=%#&redirect_uri=%#&response_type=token%22;
My code:
UIWebView *webViewInstagram = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
webViewInstagram.delegate = self;
[webViewInstagram setDelegate:self];
[self.view addSubview:webViewInstagram];
NSString *urlRedirect = #"REDIRECT_URL";
NSString *clientId = #"CLIENT_ID";
NSString *url = [NSString stringWithFormat:#"https://instagram.com/oauth/authorize/?client_id=%#&redirect_uri=%#&response_type=token",clientId, urlRedirect];
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString: url] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30];
[webViewInstagram loadRequest:request];

Display local pdf file in UIWebView in iphone

I am display local pdf file in UIWebView but it shows exception in path here is my code
NSString*fileName=content_Source;
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:#"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView setScalesPageToFit:YES];
[webView loadRequest:request]
You must be using the file name extension while setting the file name. So make sure the extension will not be used in file name if it's setting along with Type (like ofType:#"pdf").
Here's my code:
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];
There's a better way to show PDFs:
UIDocumentInteractionController *dc = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path isDirectory:NO]];
dc.delegate = self;
[dc presentPreviewAnimated:YES];
Make sure use the delegate along with that code to work it properly.
(UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller{
return self;
}
first validate that string and the assign to URL like bellow..
NSString *strURLPath = [self trimString: path];
NSURL *url = [NSURL fileURLWithPath:strURLPath];
use my bellow method...
-(NSString*) trimString:(NSString *)theString {
if (theString != [NSNull null])
theString = [theString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
return theString;
}
It is working fine with the given code problem was that in my file Name i was giving also the type like ali.pdf they type pdf so it get exception it worked fine now when i use filename like following
NSString*fileName=#"ali";
Instead of
NSString*fileName=#"ali.pdf";
CGRect rect = [[UIScreen mainScreen] bounds];
CGSize screenSize = rect.size;
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,screenSize.width,screenSize.height)];
NSString *path = [[NSBundle mainBundle] pathForResource:#"pdf" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];

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.

website not upload using webview

ihave write the following code
but it does nothing in consloe it shows Unknown scheme, doing nothing
[webview setDeleagte self];
[webView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:sourcelinkStr]]];
NSString *strURL = #"https://facebook.com";
NSURL *url = [NSURL URLWithString:strURL];
webView.delegate = self;
[webView loadRequest:[NSURLRequest requestWithURL:url]];
now ,
we have to define Methods For LoadRequest
thanks..