PDA

View Full Version : PDF viewer question




alexandergre
Sep 10, 2009, 06:10 AM
I found a tutorial on the net but cant figure it out.
In my view based application I have:

PDFViewController.h
@interface PDFViewController : UIViewController {
UIWebView *webView;
NSURL *pdfUrl;
}

@property (nonatomic, retain) IBOutlet UIWebView *webView;
@property (nonatomic, retain) NSURL *pdfUrl;

@end


PDFViewController.m
#import "PDFViewController.h"

@implementation PDFViewController

@synthesize webView, pdfUrl;

#pragma mark -
#pragma mark UIViewController methods

- (void)viewDidLoad {
[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
}


@end

where shall I have this code? in the app delegate?
:(
// Create an instance of PDFViewController
PDFViewController *controller = [[PDFViewController alloc] initWithNibName:@"PDFView" bundle:nil];
// Get the path to our documents directory
NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// This should be our documents directory
NSString *saveDirectory = [documentPath objectAtIndex:0];
// Our PDF is named 'Example.pdf'
NSString *saveFileName = @"Example.pdf";
// Create the full path using our saveDirectory and saveFileName
NSString *finalPath = [saveDirectory stringByAppendingPathComponent:saveFileName];
// Set the pdfUrl to our finalPath
controller.pdfUrl = [NSURL fileURLWithPath:finalPath];
// Push 'controller'
[self.navigationController pushViewController:controller animated:YES];
// Release 'controller'
[controller release];



dejo
Sep 10, 2009, 10:30 AM
where shall I have this code? in the app delegate?
Depends on when you want your PDF view to show up. If right when the app first starts up, then yeah, you can put it in applicationDidFinishLaunching:

alexandergre
Sep 10, 2009, 03:58 PM
EDIT: Problem REsolved. Apple documentation has some good stuff about PDF.
Thanx dejo.

Aakburns
May 22, 2010, 05:21 PM
So where does it actually go?

I've been working at this for hours now.

I tried to put it under applicationDidFinishLaunching: but I get one error for this next line.

[self.navigationController pushViewController:controller animated:YES];

The error says "Request for memeber 'navigationController' in something not a structure or union"

Please help.

Thanks.