* Display a pdf located locally

Code

– (void) displayLocalPdfInWebView
{
        CGRect rect = [[UIScreen mainScreen] bounds];
        CGSize screenSize = rect.size;

        // create the UIWebView
        UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,screenSize.width,screenSize.height)];
        webView.autoresizesSubviews = YES;
        webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);

        // specify the path of the pdf file to load
        NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"FileNameGoesHere" ofType:@"pdf"];

        NSURL *url = [NSURL fileURLWithPath:urlAddress];
        NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];

        // load it
        [webView loadRequest:urlRequest];

        // display it
        [window addSubview:webView];
        [webView release];

}

* Display a pdf located remotely

Code

– (void) displayRemotePDFInWebView
{
    CGRect rect = [[UIScreen mainScreen] bounds];
    CGSize screenSize = rect.size;

    // create the full screen webview
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,screenSize.width,screenSize.height)];
    webView.autoresizesSubviews = YES;
    webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);

    // specify the URL of the pdf located remotely on a server
    NSURL *url = [NSURL URLWithString:@"http://www.codercrunch.com/files/lesson.pdf"];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];

    // load it
    [webView loadRequest:urlRequest];

    [window addSubview:webView];
    [webView release];

}