IOS uses webview display doc/docx/xls/pdf, etc.

Source: Internet
Author: User

Add reading documentation to a project read the online document or the downloaded document, such as doc/docx/xls/pdf files.

Two methods are summarized as follows:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 1. - (void)viewDidLoad {     [super viewDidLoad];     webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, Phone_Weight, Phone_Height)];     [self loadDocument:@"1.docx" inView:webView];     webView.scalesPageToFit=YES;//点击伸缩效果的     webView.delegate=self; } - (void)webViewDidFinishLoad:(UIWebView *)webView1 {      [self.view addSubview:webView1]; }2. - (void)viewDidLoad {     [super viewDidLoad];     webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, Phone_Weight, Phone_Height)];     webView.scalesPageToFit=YES;//点击伸缩效果的     NSString *documentLocation=[[NSBundle mainBundle]pathForResource:@"1" ofType:@"docx"];     NSURL *myDocument=[NSURL fileURLWithPath:documentLocation];     NSURLRequest *request=[NSURLRequest requestWithURL:myDocument];     [webView loadRequest:request];     webView.delegate=self; } - (void)webViewDidFinishLoad:(UIWebView *)webView1 {      [self.view addSubview:webView1]; }
?
1 webView.scalesPageToFit=YES;这句很重要,不然 读出的文档不能很好的适应屏幕<br>还有一点,在工程中添加测试文档时候要在Add to targets第一项打对勾 不然路径无效,

?
1 如下:(doc文件)

?
1 <br><br>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.