Using UIWebView to display select document types

本文介绍如何使用UIWebView在iOS应用中展示多种类型的文档,包括iWork、Office文档及PDF等,并提供代码示例。

 

Q: How do I display iWork, Office, or other document types in my iPhone OS Application?

A: In addition to HTML content, UIWebView can display specific document types.

iPhone OS 2.2.1 supports the following document types:

  • Excel (.xls)

  • Keynote (.key.zip)

  • Numbers (.numbers.zip)

  • Pages (.pages.zip)

  • PDF (.pdf)

  • Powerpoint (.ppt)

  • Word (.doc)

IMPORTANT: Excel, Powerpoint and Word documents must be saved using Microsoft Office 97 or newer formats.

Keynote, Numbers and Pages documents must be created with iWork '06 or iWork '08. iWork '06 and iWork '08 documents are document packages and must be ZIP compressed for UIWebView to recognize them. You must retain both extensions in the file name, such as presentation.key.zip, spreadsheet.numbers.zip or paper.pages.zip. iWork '09 documents are not supported on iPhone OS 2.2.1.

iPhone OS 3.0 supports these additional document types:

  • Rich Text Format (.rtf)

  • Rich Text Format Directory (.rtfd.zip)

  • Keynote '09 (.key)

  • Numbers '09 (.numbers)

  • Pages '09 (.pages)

IMPORTANT: Rich Text Format Directory (.rtfd) documents are document packages and must be ZIP compressed for UIWebView to recognize them. You must retain both extensions in the file name, such as document.rtfd.zip.

iWork '09 documents do not use a package format and must not be ZIP compressed.

To display supported documents in a UIWebView, create an NSURL as a file URL with the path to the document. Listing 1 demonstrates a method that uses a UIWebView to load a document from your application bundle.

Listing 1: Loading a document into a UIWebView.

-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
    NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
}

// Calling -loadDocument:inView:
[self loadDocument:@"mydocument.rtfd.zip" inView:self.myWebview];
 
 
From: http://developer.apple.com/library/ios/#qa/qa2008/qa1630.html

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值