Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-21-2011, 09:20 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 68
mokargas is on a distinguished road
Default Preloading PDF pages

Hey there all

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?
mokargas is offline   Reply With Quote
Old 08-22-2011, 01:23 AM   #2 (permalink)
Registered Member
 
blackbook1991's Avatar
 
Join Date: Aug 2011
Posts: 20
blackbook1991 is on a distinguished road
Send a message via Yahoo to blackbook1991
Default

I suggest you use UIProgressView. So that the user would know how long he needs to wait.
__________________
Enjoy All The Way!
blackbook1991 is offline   Reply With Quote
Old 08-22-2011, 01:53 AM   #3 (permalink)
Registered Member
 
blackbook1991's Avatar
 
Join Date: Aug 2011
Posts: 20
blackbook1991 is on a distinguished road
Send a message via Yahoo to blackbook1991
Default

Maybe this project can help you. It's something like this:
__________________
Enjoy All The Way!
blackbook1991 is offline   Reply With Quote
Old 08-22-2011, 06:20 PM   #4 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 68
mokargas is on a distinguished road
Default

That's definitely one consideration - thanks blackbook1991.

However, other apps seem to load the same document a lot faster (without any progress indicators), so the answer must be out there somewhere
mokargas is offline   Reply With Quote
Old 08-22-2011, 08:16 PM   #5 (permalink)
vfr
Registered Member
 
Join Date: Jul 2011
Posts: 32
vfr is on a distinguished road
Default

Quote:
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.
vfr is offline   Reply With Quote
Old 08-22-2011, 08:20 PM   #6 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 241
MattW is on a distinguished road
Default

Quote:
Originally Posted by mokargas View Post
Hey there all

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
-----


FourSixteen Productions
MattW is offline   Reply With Quote
Old 08-22-2011, 09:40 PM   #7 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 68
mokargas is on a distinguished road
Default

Quote:
Originally Posted by MattW View Post
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?
Hey Matt. It's this one http://www.mac.sa.gov.au/file.php?f=dj~N6U.~ntxuf.1980
mokargas is offline   Reply With Quote
Old 08-23-2011, 01:19 PM   #8 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 241
MattW is on a distinguished road
Default

Quote:
Originally Posted by mokargas View Post
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
-----


FourSixteen Productions
MattW is offline   Reply With Quote
Old 09-10-2011, 02:50 AM   #9 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 68
mokargas is on a distinguished road
Default

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.
mokargas is offline   Reply With Quote
Old 09-10-2011, 02:12 PM   #10 (permalink)
vfr
Registered Member
 
Join Date: Jul 2011
Posts: 32
vfr is on a distinguished road
Default

Quote:
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.

https://github.com/vfr/Reader does this on background threads for a UI that is always responsive.
vfr is offline   Reply With Quote
Old 09-10-2011, 07:58 PM   #11 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 68
mokargas is on a distinguished road
Default

Quote:
Originally Posted by vfr View Post
It's even faster if you render the preview image once, save it out and load the preview image when you need it.

https://github.com/vfr/Reader does this on background threads for a UI that is always responsive.
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).
mokargas is offline   Reply With Quote
Reply

Bookmarks

Tags
ios, nsoperationqueue, pdf

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 397
14 members and 383 guests
7twenty7, chiataytuday, cristofercolmbos, dedeys78, fiftysixty, gmarro, iOS.Lover, jonathandeknudt, Matrix23, raymng, stanny, tymex, UMAD, xerohuang
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,669
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dedeys78
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:12 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0