How to Previewing documents on Iphone

4294

iphone51

Just like on the Macintosh, the iPhone SDK contains a technology known as Quick Look for previewing documents. By using a CLP review Controller object, you can easily view multiple documents of several formats, including Microsoft Office, Apple work, PDF, rich text, images, and more. Next you’ll see how, with just a couple of lines of code, you can create a simple PDF viewer, complete with paging and touch enabled resizing. This example can, of course, be extended to work with any of the document types supported by Quick Look. In this example, you’ll view the iPhone Users Guide, which can be downloaded from Apple at http://manuals.info.apple. com/en/iphone_user_guide.pdf.

To create a PDF viewer:
1. Create a new view-based application, saving it as Quick Look Example.
2. Drag the iPhone Users Guide PDF into the Resources section in the Groups & Files pane. Make sure that the “copy items into destination group’s folder (if needed)” check box is selected F.
3. In the Groups & Files pane, expand the Targets section, right-click your application target, and select Get Info.
4. Making sure the General tab is selected, click Add (+) at the bottom of the Linked Libraries list, and add the
Quick Look framework G.
5. Open Quick Look Example View Controller .h, include the Quick Look.h header, add the protocol QLP review Controller Data Source, and create an instance variable to hold your Quick Look view controller (Code Listing 6.4).
6. Next, switch to Quick Look Example View Controller .m, uncomment the view Did Load method, and add the following code: live Controller = [[QLP review Controller allot] init]; ql View Controller. Data Source = self; [self create]; Here you are simply creating a Quick Look preview controller and setting its data source. You also call the create method, which adds the button that will be used to show the Quick Look preview controller.
7. Next, create the show Preview method: [self present Modal View Controller: ql View Controller animated: YES]; which simply shows the Quick Look preview controller on the screen.

8. Now you need to implement the two QLP review Controller Data Source data source methods so that the Quick Look preview controller knows what to display. First you implement the number Of Preview Items in Preview Controller: method. In this example, since we have only a single PDF file,
You simply return the number 1. Return 1; you then implement the preview Controller: preview Item at Index:
Method: Nesting *document Location = [[Unbundle main Bundle] path For Resource:@”iphone_user_guide” ofType:@”pdf”];NSURL *myQL Document = [NSURL file URL with Path: document Location]; return myQLDocument; Here you retrieve the path of your PDF and use it to create and return an NSURL object.
Code Listing 6.5 shows the completed code.

9. Build and run the application tapping the Show Preview button causes the Quick Look preview controller
to load . You can navigate through the pages of the PDF by flicking your finger up and down on the screen. Note how your current page is displayed in the top-right corner and the document name is displayed in the title bar H. By pinching or double-tapping the screen, you should be able to zoom in to read the document in greater detail. For more information on Quick Look, refer to the Quick Look Framework Reference in the developer documentation.

BIO:

Sussan Deyhim is from Electrician Durham and a University Lecturer. She loves to write on technical topics like Electrician Chapel Hill. She is writing from last three years