I need to create an iPad application that will display several PDF files (one file contains one page). Each page should be scrollable, scalable, and if the user clicks on a part of the PDF, a website or photo gallery should appear.
Currently, I think I can do this with:
a. UIWebView
Displays work, convenient, scrollable and scalable. But there seem to be a lot of problems for implementing clickable parts of PDF.
V. Quartz
I found several resources describing how to display PDF directly through Quartz. See: http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html
- This will allow the use of CGPDFContextSetURLForRect
- But I have no idea if this will be similar to UIWebView - scrolling and scaling support out of the box?
Can anyone enlighten me on this?
Thank you for your time!
[Edit: changed from 3.0 to 3.2] [Change: my "solution"]
Hello!
I could create a working implementation for PNG, but not for PDF.
[Summary] My solution was to render the content, intercept its touches, return the coordinates relative to the displayed content, if it is a single touch, and finally, find out what to do with a display containing interactive areas as coordinates and what to do if they click on.
[For PNG] It was more cumbersome to implement something like this than I could imagine ... And the implementation that I received is highly dependent on the content you want to display, because it works for UIImageView, but I could not get it to work with UIWebView.
First you need UIScrollView and UIImageView to display content and support scrolling / scaling. Then you need to implement some processing to get the strokes / gestures you are interested in. See: Developer.apple.com/iphone/library/samplecode/ScrollViewSuite/Listings/1_TapToZoom_Classes_TapDetectingImageView_h.html
This apple sample provides everything you need for this part to work. As a bonus, he also takes care of transforming coordinates relative to the content viewport, which is very convenient! (otherwise you would only know where the icon appears on the screen that contains only one half of the necessary information if your content is scaled / scrolled)
[For PDF] If you want to do this using PDF, the first thing you need is to use UIWebView (maybe you could do it via Quartz or something else)
Getting strokes with UIWebView is a real pain! There are many ways on the Internet, and besides, no one did what they were supposed to do. After several days of searching, I found this gem: cocoawithlove.com/2009/05/intercepting-status-bar-touches-on.html
So ... subclassing UIWebView doesn't give you anywhere, unlike UIImageView, and you need to subclass UIApplicationMain and implement its touch event handling method. Here you can reuse the "Touch-Handling-Stuff" portion of the apple example above.
Now you will need to translate the touch coordinates to your content if it is scaled / scrolled. UIWebView does NOT do this for you, unlike UIImageView!
I could never understand how to get the required information (which part of the content on which it is scaled) from UIWebView to translate coordinates, but because of the changed requirements from PDF to PNG, I did not want it to work too much.
hope this helps.