0
votes

I'm trying to display the local .doc files in UIWebView from main bundle.

I added the following code to display in UIWebView.

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"LocalDocument" withExtension:@"doc"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[self.webView loadRequest:theRequest];

UIWebview displays the document correctly, But the problem is it doesn't display the text "Header" in correct font size in iPhone.

iPhone screenshot iPhone screenshot

iPad screenshot iPad screenshot

In the word document I added the text "Header" with font size 22 and description text with font size 14.

In iPad it displays correctly, but in iPhone it display both text in font size 14.

Has anyone encountered this problem?

1

1 Answers

0
votes

Use this

NSString*fileName= @"LocalDocument";
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"doc"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path isDirectory:NO]];
[webView setScalesPageToFit:YES];
[webView loadRequest:request];
[self.view addSubview:webView];

And use custom font for UIWebview

NSString *myText=[NSString stringWithFormat: @"<html><body><script>var str = '%@'; document.write(str.fontsize(%d).fontcolor('green'));</script></body></html>",myString,textFontSize];