On the iPhone, you can easily preview document files, such as pdf and word. This document takes PDF as an example. This article introduces three methods to preview PDF files, and compares them with local pdf files on the network.
Preview local PDF files:
1. Use the UIWebView Control
UIWebView is one of the most commonly used controls in iPhone development, similar to the webBrowser control in. net. Using it to preview PDF files is quite convenient and simple.
The key code for previewing a PDF file in UIWebView is as follows:
Effect:
2. Use CLPreviewController
CLPreviewController is a new feature that allows you to quickly preview a document and preview it while loading it. In other words, you do not need to load all the documents to the memory.
To preview a PDF file using CLPreviewController, You need to implement a delegate: QLPreviewControllerDataSource. The key code is as follows:
PrevoewController returns the address of the preview file.
This method is not only fast, but also provides a function to print documents on the iphone, such.
3. Drawing pdf documents
Apple has an official example of drawing pdf. This method can easily control the details of pdf presentations, but the efficiency is not high.
Preview PDF files on the network:
1. Use UIWebView to preview PDF documents on the network. First, download the documents to be previewed to the iPhone memory, and then preview the documents. For large pdf documents, the efficiency is not high, user experience is also poor.
2. For prevoewController, because it is loaded step by step, all pdf documents are not loaded at a time. The user experience is good, but a print button is added to 4.0, when you click the print button, the program goes down. It's a cup.
3. The rendering method also needs to be loaded to the memory at a time, and the rendering efficiency is not high. This method should not be used for large documents.
Solution for previewing large network documents:For pdf files on the network, for example, e-books (some e-books are relatively large), we recommend that you first download them to your local device and then preview them in the second way.
Summary:This article introduces three methods to preview pdf documents, similar to non-pdf documents. I am not familiar with iPhone development, and I am not sure what I have written. please correct me.
Code:Http://files.cnblogs.com/zhuqil/PDFView.zip
Author:Zhu Yulin