Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDF View with horizontal scroll

I'd like to get some tip about how implement a PDF View that scrolls horizontally.

I know how implement a PDF reader using UIWebView, but just with vertically scroll.

like image 627
Fernando Aureliano Avatar asked Jul 05 '11 19:07

Fernando Aureliano


2 Answers

I've done this. The code was private for a paying customer, so I can't share it directly, but the basic idea is to write:

  • One UIView subclass that renders a single page of a PDF, using a CGPDFPageRef and the CGPDFDocument* and CGContextDrawPDFPage families of functions. It helps a great deal for this view to return [CATiledLayer class] from the layerClass class method, and to set the layer's levelsOfDetail and tileSize properties appropriately. Mine also implements sizeThatFits to return the page size plus a small gutter, and renders a subtle dropshadow around the edge of the pdf page.

    Remember that UIKit drawing is upside-down from CG drawing; so do a CGContextTranslateCTM(ctx, 0.0, layer.bounds.size.height); CGContextScaleCTM(ctx, 1.0, -1.0); before painting.

  • One UIView subclass containing and laying out (and being delegate for) a UIScrollView in paging mode (the main horizontal pager), and an individual UIScrollView for each page, each containing one of the above views (for zooming into individual pages.) Nested scroll views is Apple's explicitly endorsed way of doing this sort of thing. This view will need to lay out the pages how you want them; presumably in one long horizontal strip, each zoomed to a fitting size.

    If you don't need page zooming, you can skip the nested scroll views and lay out the page views directly in the horizontal scroller.

TL;DR: Unfortunately it's not as simple as tossing it in a UIWebView; but it is doable, and the straightforward approach does work.

like image 147
rgeorge Avatar answered Oct 01 '22 10:10

rgeorge


I found an open project with this feature =D

https://github.com/iamruinous/Reader

like image 38
Fernando Aureliano Avatar answered Oct 01 '22 12:10

Fernando Aureliano