I'm currently developing a simple PDF reader (as my numerous posts no doubt attest!) and it's going swell.
I have a tableview which contains cells that link to different documents. Select one of these documents and a PDF loads in a simple viewcontroller.
There's a problem though.
Some of these PDF's are large and heavy. For instance, one of the documents has a full page 24-bit image as a background (Daft, I know, but out of my hands). When you first load the viewcontroller with this document, the first page takes a while to appear initially (up to 20 seconds), though will scroll fine after that initial hit. Overall it hurts the responsive feel of the app.
I considered using an NSOperationQueue to create a thread for the first PDF page for each document, however I'm not sure on how to do this in the context of the initial tableview. Do I create an NSOperation to generate the first page view for each possible document I can select and store that view (seems wasteful) or is there another way?
When you first load the viewcontroller with this document, the first page takes a while to appear initially (up to 20 seconds)
Sounds like you could be doing a lot of work in any one of a UIViewController's init/setup/appear (initWithNibName, viewDidLoad, viewWillAppear, etc.) methods before the UIViewController is visible. Have a look at my open source PDF viewer/reader for the various tricks that I used to make things come up quick and be responsive all the time.
I'm currently developing a simple PDF reader (as my numerous posts no doubt attest!) and it's going swell.
I have a tableview which contains cells that link to different documents. Select one of these documents and a PDF loads in a simple viewcontroller.
There's a problem though.
Some of these PDF's are large and heavy. For instance, one of the documents has a full page 24-bit image as a background (Daft, I know, but out of my hands). When you first load the viewcontroller with this document, the first page takes a while to appear initially (up to 20 seconds), though will scroll fine after that initial hit. Overall it hurts the responsive feel of the app.
I considered using an NSOperationQueue to create a thread for the first PDF page for each document, however I'm not sure on how to do this in the context of the initial tableview. Do I create an NSOperation to generate the first page view for each possible document I can select and store that view (seems wasteful) or is there another way?
20 seconds sounds like an awfully long time if the file is local to the device. Are you displaying the PDF locally, or from the web? If it's from the web it might just be a download time issue.
Can you provide a link to the PDF?
__________________
Highlight PDF text like no other app: iHighlight (now available for iPad and iPhone!)
-----
Create iPhone lists with no typing: Insta-List
-----
Make spelling fun, and create your own tests: iWillSpell
-----
A fast, elegant flashlight app: Insta-Light
-----
20 seconds sounds like an awfully long time if the file is local to the device. Are you displaying the PDF locally, or from the web? If it's from the web it might just be a download time issue.
I've downloaded and viewed that PDF in my app, iWillHighlight (I tested it on both iPad 1 and iPhone 4) and that PDF is certainly a little sluggish when it comes to displaying, but nothing like the 20 seconds you're talking about. The first page takes about 2.5 seconds to display, and that's including the custom parsing that my app does to extract the text and positional data.
The interesting thing is that the majority of the pages are nothing more than a full-page picture with a few words on top. Typically, in PDF rendering, it's drawing the text that takes up the time. Rendering bitmaps is quite quick. My guess is that these bitmaps are scaled (not pre-scaled and put in the document, but scaled with the PDF commands so it has to do it every time the page is displayed) and if the app has set the anti-aliasing quality to best, then it's going to take a little while to process the image data.
I'm not sure why your app is taking 20 seconds to display the first page... post your code so we can take a look.
__________________
Highlight PDF text like no other app: iHighlight (now available for iPad and iPhone!)
-----
Create iPhone lists with no typing: Insta-List
-----
Make spelling fun, and create your own tests: iWillSpell
-----
A fast, elegant flashlight app: Insta-Light
-----
Managed to figure this out, turns out when I was removing memory warnings from the app, I found that I was triple (!!!) retaining the CGPDFDocumentRef (costing 4+ mb at a time).
Removing this and adding fast UIImage page rendering prior to the CATiledLayer being rendered improved load time massively. A medium quality image of the page loads in < 250ms with the high resolution tiled layer appearing smoothly over the top in around 2 seconds.
Removing this and adding fast UIImage page rendering prior to the CATiledLayer being rendered improved load time massively. A medium quality image of the page loads in < 250ms with the high resolution tiled layer appearing smoothly over the top in around 2 seconds.
It's even faster if you render the preview image once, save it out and load the preview image when you need it.
Just implemented something very similar and saved the first/current page preview into the app's Core Data store. It's amazing how a change in thinking can have immense real world benefits (and also a good deal less code)
I haven't seen your Reader since ~1.0, vfr, and I noticed you've added PDF links which is awesome ! Next move for me is to get embedded video / audio to work.
I've also gone the small thumbnail route, but I still use a custom slider (basically you drag the slider and a thumbnail appears above the handle/touch location).