views:

591

answers:

2

Hello!

I'd need to create a iPad-app which would be rendering multiple PDF-Files (one file contains one page). Each page should be scrollable, zoomable and if the user taps on a part of the PDF a website or photo gallery should popup.

Currently i think i could do that either with:

A. UIWebView

Displays the pdf's nicely, scrolling and zooming works. But it looks like a lot of trouble to realize the clickable parts of the PDF.

  1. I don't know if i could use CGPDFContextSetURLForRect
  2. Getting the touch-events from UIWebView to do something like CGPDFContextSetURLForRect my self looks like it would be some "quite bad" hack. See: http://github.com/psychs/iphone-samples/blob/master/WebViewTappingHack/Classes/PSWebView.m

B. Quartz

I found some resources describing how to display PDF's directly via Quartz. See:http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html

  1. This would allow using CGPDFContextSetURLForRect
  2. But i have no idea if this would - like UIWebView - support scrolling and zooming out of the box?

Anybody could enlighten me on this please?

Thanks for your time!

[Edit: changed 3.0 to 3.2] [Edit: my "solution"]

Hi!

I could come up with a working implementation for PNG but not for PDF's.

[Abstract] My sollution was Rendering the content, intercepting the touches on it, retreiving the coordinates relative to the displayed content if it is one touch and finally looking up what to do from a mapping containing the interactive areas as coordinates and what to do if they get clicked.

[For PNG] It was way more cumbersome to implement somethink like that than i would have imagined... And the implementation i got working depends heavily on the content you want to display because this does work for UIImageView but i could not get it working with UIWebView.

First you need a UIScrollView and UIImageView to render the content and support scrolling/zooming. Then you need to implement some handling to get the touches/gestures you are interested in. See: developer.apple.com/iphone/library/samplecode/ScrollViewSuite/Listings/1_TapToZoom_Classes_TapDetectingImageView_h.html

This sample from apple provides everything you need to get this part working. As a bonus it also takes care about transforming the coordinates relative to the viewport of the content which is very handy! (else you would only know where the tap happend on the screen wich only one half of the info you need if your content is zoom-/scrollable)

[For PDF] If you want to do this with PDF the first thing would be that you need to use a UIWebView (probably you could do it via Quartz or something else too)

Getting the touches with a UIWebView is a real pain! There are a lot of ways proposed on the web and besides one noone did what it should do. After days of googling i found this gem: cocoawithlove.com/2009/05/intercepting-status-bar-touches-on.html

So... subclassing UIWebView does not get you anywhere unlike UIImageView and you have to subclass UIApplicationMain and implement its method for handling touch-events. Here you could reuse some of the "Touch-Handling-Stuff" from the apple-examlpe from above.

Now you would need to translate the coordinates of the touch to your content if it is zoom-/scrollable. UIWebView DOES NOT do this for you unlike UIImageView!

I could never figure out how to get the required information(what part of the content at which zoomlevel) from a UIWebView to translate the coordinates but due to the changed requirements from PDF to PNG i didn't care to get it working too much.

hope this helps.

A: 

Demonic Tutor,

Where you ever able to find a solution to this? I face a similar issues.

Cheers,

PJ

Peter
edited my question to include my sollution
DemonicTutor
A: 

Using the CGPDF* operators will allow you to write a UIPDFView, which operates exactly as UIImageView but uses a PDF as the source image. Create your own custom subclass of UIView and implement drawRect: to, eventually, call CGContextDrawPDFPage. Based on a quick Google search (because I know the keywords), this page seems to explain that side of things quite well.

You can then directly substitute your custom UIView subclass for the UIImageView and proceed exactly as you have with the PNG solution.

Tommy