Note that there are some explanatory texts on larger screens.

plurals
  1. POFast and Lean PDF Viewer for iPhone / iPad / iOs - tips and hints?
    primarykey
    data
    text
    <p>There has been many Questions recently about drawing PDF's. </p> <p>Yes, you can render PDF's very easily with a <code>UIWebView</code> but this cant give the performance and functionality that you would expect from a good PDF viewer.</p> <p>You can draw a PDF page <a href="http://www.cocoabuilder.com/archive/cocoa/196313-display-pdf-in-calayer.html" rel="noreferrer">to a CALayer</a> or <a href="https://stackoverflow.com/questions/3831304/calayer-and-off-screen-rendering/3853778#3853778"> to a UIImage</a>. Apple even have sample code to show how draw a large PDF <a href="http://developer.apple.com/library/ios/#samplecode/ZoomingPDFViewer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010281" rel="noreferrer">in a Zoomable UIScrollview</a></p> <p>But the same issues keep cropping up.</p> <p><strong>UIImage Method:</strong></p> <ol> <li>PDF's in a <code>UIImage</code> don't optically scale as well as a Layer approach.</li> <li>The CPU and memory hit on generating the <code>UIImages</code> from a <code>PDFcontext</code> limits/prevents using it to create a real-time render of new zoom-levels.</li> </ol> <p><strong>CATiledLayer Method:</strong></p> <ol start="3"> <li>Theres a significant Overhead (time) drawing a full PDF page to a <code>CALayer</code>: individual tiles can be seen rendering (even with a tileSize tweak)</li> <li><code>CALayers</code> cant be prepared ahead of time (rendered off-screen).</li> </ol> <p>Generally PDF viewers are pretty heavy on memory too. Even monitor the memory usage of apple's zoomable PDF example.</p> <p>In my current project, I'm developing a PDF viewer and am rendering a <code>UIImage</code> of a page in a separate thread (issues here too!) and presenting it while the scale is x1. <code>CATiledLayer</code> rendering kicks in once the scale is >1. iBooks takes a similar double take approach as if you scroll the pages you can see a lower res version of the page for just less than a second before a crisp version appears.</p> <p>Im rendering 2 pages each side of the page in focus so that the PDF image is ready to mask the layer before it starts drawing.Pages are destroyed again when they are +2 pages away from the focused page.</p> <p><strong>Does anyone have any insights, no matter how small or obvious to improve the performance/ memory handling of Drawing PDF's? or any other issues discussed here?</strong></p> <p><strong><em>EDIT:</em></strong> Some Tips (Credit- Luke Mcneice,VdesmedT,Matt Gallagher,Johann):</p> <ul> <li><p>Save any media to disk when you can.</p></li> <li><p>Use larger tileSizes if rendering on TiledLayers</p></li> <li><p>init frequently used arrays with placeholder objects, alternitively another design approach is <a href="http://cocoawithlove.com/2009/01/multiple-virtual-pages-in-uiscrollview.html" rel="noreferrer">this one</a></p></li> <li><p>Note that images will render faster than a <code>CGPDFPageRef</code></p></li> <li><p>Use <code>NSOperations</code> or GCD &amp; <a href="http://thirdcog.eu/pwcblocks/" rel="noreferrer">Blocks</a> to prepare pages ahead of time.</p></li> <li><p>call <code>CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh); CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);</code> before <code>CGContextDrawPDFPage</code> to reduce memory usage while drawing </p></li> <li><p>init'ing your <code>NSOperations</code> with a docRef is a bad idea (memory), wrap the docRef into a singleton.</p></li> <li><p>Cancel needless <code>NSOperations</code> When you can, especially if they will be using memory, beware of leaving contexts open though!</p></li> <li><p>Recycle page objects and destroy unused views</p></li> <li><p>Close any open Contexts as soon as you don't need them</p></li> <li><p>on receiving memory warnings release and reload the DocRef and any page Caches</p></li> </ul> <p><strong>Other PDF Features:</strong></p> <ul> <li><p><a href="https://stackoverflow.com/questions/3257057/iphone-cgpdfdocument-pdf-links">Getting Links inside a PDF</a> (and <a href="https://stackoverflow.com/questions/4080373/get-pdf-hyperlinks-on-ios-with-quartz">here</a> and <a href="http://pastebin.com/69JW1Kkc" rel="noreferrer">here</a>)</p> <ul> <li><p><a href="https://stackoverflow.com/questions/4255298/how-does-an-annot-cgpdfdictionary-rect-translate-to-objective-c-points/4255586#4255586">Understanding the PDF Rect for link positioning</a></p></li> <li><p><a href="https://stackoverflow.com/questions/4303394/converting-adobe-pdf-date-string-to-nsdate">Converting PDF annot datestrings</a></p></li> <li><p><a href="https://stackoverflow.com/questions/4643489/how-do-i-retrieve-a-page-number-or-page-reference-for-an-outline-destination-in-a/4683905#4683905">Getting the target of the link</a> (Getting the page number from the <code>/Dest</code> array)</p></li> </ul></li> <li><p><a href="https://stackoverflow.com/questions/2556344/create-a-table-of-contents-from-a-pdf-file">Getting a table of contents</a></p></li> <li><p><a href="https://stackoverflow.com/questions/5881921/get-cgpdfdocumentref-name-of-document/5912618#5912618">Document title</a> and <a href="http://www.iphonedevsdk.com/forum/iphone-sdk-development/29770-pdf-title-keywords-label.html" rel="noreferrer">Keywords</a></p></li> <li><p><a href="https://stackoverflow.com/questions/2556344/create-a-table-of-contents-from-a-pdf-file/3427596#3427596">Getting Raw Text</a> (and <a href="https://stackoverflow.com/questions/2960195/extracting-pdf-text-in-objective-c">here</a> and <a href="https://stackoverflow.com/questions/3627745">Here</a> and <a href="https://stackoverflow.com/questions/3627745/getting-text-position-while-parsing-pdf-with-quartz-2d">here</a> (positioning focused))</p></li> <li><p><a href="http://blog.random-ideas.net/?p=184" rel="noreferrer">Searching</a>(and <a href="https://stackoverflow.com/questions/4097044/pdf-search-on-the-iphone">here</a>) (doesn't work with all PDFs (some just show weird characters, I guess it's an encoding issue but I'm not sure) -Credit BrainFeeder)</p></li> <li><p><a href="https://stackoverflow.com/questions/3831304/calayer-and-off-screen-rendering">CALayer and Off-Screen Rendering</a> - render the next page for fast/smooth display</p></li> </ul> <p><strong>Documentation</strong></p> <ul> <li><a href="http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGPDFObject/Reference/reference.html" rel="noreferrer">Quartz PDFObjects</a> (Used for meta info, annotations, thumbs) </li> <li><a href="http://www.adobe.com/devnet/pdf/pdf_reference.html" rel="noreferrer">Abobe PDF Spec</a> </li> </ul> <p><strong>Example projects</strong></p> <ul> <li><a href="http://developer.apple.com/library/ios/#samplecode/ZoomingPDFViewer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010281" rel="noreferrer">Apple/ ZoomingPDF</a> - zooming, <code>UIScrollView</code>, <code>CATiledLayer</code></li> <li><a href="https://github.com/vfr/Reader" rel="noreferrer">vfr/ reader</a> - zooming, paging, <code>UIScrollView</code>, <code>CATiledView</code></li> <li><a href="https://github.com/brow/leaves" rel="noreferrer">brow/ leaves</a> - paging with nice transitions </li> <li><a href="http://skim-app.sourceforge.net/developers.html" rel="noreferrer">/ skim</a> - everything it seems (PDF reader/editor for OSX)</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload