Yang Jie Domodomo Yang Jie Domodomo - 2 months ago 13x
iOS Question

how to display pdf on ios

I'm still pretty new to

, although I did many tutorial and online research before, there are still a few things which puzzle me as obj c is not my native programming language. (self-learned on my intern)

I want to know if there is any way for a offline build for
xcode iOS
such that we can display pdf file from local file.

The method I'm using now is via
to display a custom HTML which contain the PDF URL (online) , but I want to make an offline version if possible.

But from online research, it seems to me the only way to display PDF is via UIWebView, if that is really the case, is it possible to pull the file from local resource (e.g. add files to my xcode resource folder) rather than using the PDF URL.

Which would be a better choice? To pull local file or to use the online URL for PDF file?

require connection, it would seem to be a better choice to just pull the online URL as it will be the most current and updated.

Feedback is very much appreciated. Thanks!

EDIT: quick question, if I use the
method or the QuickLook framework to make it offline, this would mean I have to release update patch each time there is new PDF article added in (correct me if I'm wrong)

Taking this point into consideration, I've come up with a counter-argument to my own question on the spot (Sorry if any of you feel you are wasting time on me >.<, I am a person who like to question possibilities and the different approach one could take to solve a problem)
In the event to save time from the constant updating and providing a real time base solution, which is to use UIWebView (I know this is contradicting my purpose of this SO thread), as this proj is base on a online website (getting my content and sources from there), if I were to load their website for the article section, would it be bold of me to say that by adding a NSString variable, I can add in the NSRange function to the viewDidLoad together with the UIWebView such that the URL will never leave the news section and PDF URL. e.g. using combination of if and NSRange function to counter check that the URL only contain the news section and PDF URL)

I did once before a NSRange function for point on calculator so I thought it would be a good time to put it in use for this framework app.

P.S - This app is a organization base project and I'm a intern providing them with the base skeleton framework.


You can use a UIWebView to get the PDF from your bundle directly, no need to call an online web service.

Local File:

NSString *html = [NSString stringWithContentsOfFile:path1 encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]bundlePath]]];

Remote File:

- (void) loadRemotePdf
       CGRect rect = [[UIScreen mainScreen] bounds];
       CGSize screenSize = rect.size;
       UIWebView *myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,screenSize.width,screenSize.height)];
        webView.autoresizesSubviews = YES;
            webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);

       NSURL *myUrl = [NSURL URLWithString:@"http://www.mysite.com/test.pdf"];
       NSURLRequest *myRequest = [NSURLRequest requestWithURL:myUrl];
       [webView loadRequest:myRequest];

       [window addSubview: myWebView];
       [myWebView release];