views:

104

answers:

2

Hi - I am using the following (simple) code to load a PDF from the documents folder in my app into a UIWebView. The performance is very poor. I tried loading the same PDF from the web via Safari and the performance was great. Does anyone have any ideas? (this viewController is being presented as a modalViewController).

- firstView.m

InfoViewController *mcontroller = [[InfoViewController alloc] init];

        NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                             NSUserDomainMask, YES);
        NSString *docsPath = [paths objectAtIndex:0];


NSString *pathToPDF = [NSString stringWithFormat:@"%@/myPDF.PDF",docsPath];

NSURL *targetURL = [NSURL fileURLWithPath:pathToPDF];

mcontroller.urlToFile = targetURL;
[self presentModalViewController:mcontroller animated:YES];

modalViewController.m -

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURLRequest *request = [NSURLRequest requestWithURL:urlToFile];

    [webView loadRequest:request];




}
A: 

The first thing I would look at is the PDF its self. Often people try loading huge PDF files and expect them to perform wonderfully. Can you post the PDF for us to see? How large is the file? Remember that the PDF file size is the compressed size, to display images in the PDF they will be uncompressed when stored in RAM. Its not uncommon for a 500KB image on disk to use 20 MB in memory (This applies for all raster graphics, not just PDFs). This is usually the case when PDF performance is poor from what I've seen around here.

I know you said it works great in Safari, however we don't know what all Apple does in Safari's internals vs a UIWebView. Also Safari is usually running in the background, so it is using memory even when your app is running. This reduces mem that you app can use, but when you are running safari as the foremost app, 3rd party apps aren't using much memory, so safari could potentially cache more of the PDF at a time.

jamone
the pdfs are 1-5 MB, but there are no images in the PDF. I dont know enough about PDFs to know whats really going on. http://www.noahbryant.com/LAHSO.PDF
Brodie
That particular PDF runs with no lag whatsoever in Safari, but in my app it lags for about .5 second on each page.
Brodie
For some reason Instruments isn't working correctly for me in iOS right now, but in OS X Safari 5 that PDF causes a 35 MB mem usage increase over a blank HTML page. That would be a lot for iOS if that result is similar to what's happening in your app. I don't know what about the NOAA IFR and AFD PDF makes them so complex since they typically do use quite a bit of RAM from my tests a while ago. The other thing that may cause issues is how many views are loaded? I know this is in a Modal view, but is the viewController below this complex? The more subviews the more complex/slower it will be.
jamone
there really isn't much going on. It's using about 6MB or so displaying some graphics, but there's actually nothing running in the app besides the PDF at the time it's displayed. Im going to try making a simple test app that does nothing but display this pdf, to see if that's the problem
Brodie
A: 

I ended up using the documentInteractionController for this to display the PDF in Quick Look. There is a great tutorial for this in the 2010 WWDC vids.

No idea why it wasn't working well in webView, but it's smooth as silk in Quick Look.

Brodie