File Formats Supported by UIWebView - iphone

What are all the file formats supported by UIWebView?
In my testing, I found that it supports XLS, DOC, PPT, PDF but not XLSX, and DOCX, RTF.
It supports image files like, JPG, PNG, GIF, BMP, not sure about TIFF or
Exactly, what all types are supported is not clear...
The UIWebView documentation also doesn't state it clearly.
Could someone please help?

A Technical note is available on Apple Website about file formats supported by UIWebView:
Since iPhone OS 2.2.1
Excel (.xls)
Keynote (.key.zip)
Numbers (.numbers.zip)
Pages (.pages.zip)
PDF (.pdf)
Powerpoint (.ppt)
Word (.doc)
Since iPhone OS 3.0
Rich Text Format (.rtf)
Rich Text Format Directory (.rtfd.zip)
Keynote '09 (.key)
Numbers '09 (.numbers)
Pages '09 (.pages)

I am seeking a definitive answer on this, too.
While the Tech Note tells us which high-level formats are supported, it doesn't tell us which simple formats, e.g. image types, are supported. I need that information, though, in order to let a web server know which formats it can send me (i.e. via http's "Accept" header).
Update
Uh, actually, here's the docs from Apple on supported image formats by UIWebView: http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/GraphicsandDrawing/GraphicsandDrawing.html#//apple_ref/doc/uid/TP40007072-CH10-SW8

.rtf files are apparently supported but I was unable to get the UIWebView to display them properly. It would format the text correctly (size, colour, font etc) but images just plain didn't render (I tried .gif, .png and .jpg to no avail). chances are if you are going to the trouble of using .rtf, you are probably hoping to display images in the UIWebView, since the main benefit of rtf is that you can embed images into the file. This was tried on an actual iPad 1 (4.3) and on a simulated iPhone (4.3).
The code done to display the rtf in a UIWebView required the rtf to be written to a file with the rtf file extension. It refused to load the file if you use no file extension or an incorrect one so make sure you write it as .rtf.
Here is an Objective C function to take an input string (which should contain the rtf you wish to display) and get the UIWebView to load it into view...
-(void) loadRtf : (UIWebView*) webView : (std::string) rtfFile
{
// This function will write the rtf to a file in your apps bundle location on the iDevice and use
// the UIWebView to load it...
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([path count] > 0) ? [path objectAtIndex:0] : nil;
NSString *fullPath = [basePath stringByAppendingPathComponent:#"rtfData.rtf"];
std::string fp = [fullPath cStringUsingEncoding:NSASCIIStringEncoding];
std::ofstream fs;
fs.open(fp.c_str(), std::ios_base::binary);
if( !fs.is_open() )
return;
fs << rtfFile;
fs.close();
NSURL *url = [NSURL fileURLWithPath:fullPath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}

Related

How to embed font into PDF file displayed in UIWebview?

I am opening a pdf file downloaded from server into UIWebview. However, the pdf opens correctly into the web view, but there is an error displayed on console:
LLALCK+MyriadPro-SemiboldIt: FT_Select_Charmap failed: error 6
After some r&d I found that this issue is related to fonts.
I would like to know how to embed fonts within the pdf, so that the above error is eliminated. I tried installing font.otf file on Mac and tried to run pdf display on simulator, but it still gives same error.
Following is the code which I use to display pdf in uiwebview:
NSData* data = [NSData dataWithContentsOfFile:path];
[webView
loadData:data
MIMEType:#"application/pdf"
textEncodingName:#"UTF-8"
baseURL:nil];
Please help.
Badly stuck!
Thanks in advance.
The problem is your PDF references a font which the device does not have. You could try adding this font to your bundle, but this can be problematic in several key areas.First, I am not sure WebView can read custom fonts for the purpose of PDFs; but more importantly, second, you likely do not have a license to embed that font in your application.
I would suggest tackling this problem from a different perspective. How is your PDF created on the server? Either use a safe font in your PDF (see a full list of iOS fonts here), or use the font embedding feature of PDF and use that. Fonts usually come with a more relaxed license when embedding certain glyph in PDFs.

HTML file creation with image

I created an HTML file programmatically with images sources. The images are stored in the documents directory. The problem is that when I give the image source path as document directory path the images are not shown in Windows.
So, I choose the second option is to give only the image's name instead of whole path. Then it work well on Mac & Windows, but now images are not shown on the device's UIWebView.
Then I selected to open the HTML file in Safari insted of UIWebView, but the safari could not be opened because URL becomes NULL.
My code to open Safari is as follow:
NSLog(#"%#",documentsDirectory);
NSString *urlStr = [NSString stringWithFormat:#"%#/AccReport1.html",documentsDirectory];
NSLog(#"urlStr :: %#",urlStr);
NSURL *url1=[[NSURL alloc]init ];
url1 = [NSURL fileURLWithPath:urlStr];
NSLog(#"url :: %#",url1);
[[UIApplication sharedApplication]openURL:url1];
I want to mail the HTML file that contains images. And these HTML file and images are stored in document directory. I want to show this HTML file with images in windows browser, mac browser and iphone's safari.
How to do this?
One of the simple way to solve your problem is to keep Images and HTML file in same directory and refer those images in HTML files just by name and if you put them in a folder then give the complete path.
The images are not showing because the image path specified within the HTML code is not the documents directory path.
I suggest you might have to construct an html string and then subject the uiwebview to load that string
NSString *htmlString = [NSString stringWithFormat:#"<html><body><img src=\" %#/image.png \"></img></body></html>",documentsDirectoryPath];
[webView loadHTMLString:htmlString baseURL:nil];

How to change file extension from .txt to .rtf in ios programmatically?

How do I change a file extension from .txt to .rtf in iOS programmatically?
In xml parsing I'm getting rtf data with rtf tags.
Is it possible to save data in a rtf file without tags?
If we load that file, this was loading with rtf tags in webview.
If we open and save that file physically, it opens in the WebView.
Is there any way to do this task (File Open & Save) programmatically using iOS.
If we load the rtf file from FTP server, upto tables it was loading(only plain text before tables)
using function of NSString
NSString *string2 = [[NSString alloc] initWithContentsOfFile:#"whateverFile.rtf"];
get the text only from the file and save it in .txt format using the
NSMutableString *mutstr2 = [[NSMutableString alloc] init];
[mutstr2 setString: string2];
[mutstr2 writeToFile:#"whatevertxt.txt" atomically:YES encoding:NSUnicodeStringEncoding error:&error];
you could write the file in .txt. format... i guess that is the best way to do what u want

loading and formatting the rtf file in UIWebView

I am trying to load the contents of a rtf file in the UIWebView. I am successful in loading the contents, but it is unformatted. the fonts are too large and it doesn't have any format. it displays the color of the rtf content, but not the font or size.
So what should i do now. is there any other way to load the rtf and format it? I load the rtf in following way:
NSString *path = [[NSBundle mainBundle] pathForResource:#"Home" ofType:#"rtf"];
NSURL *url=[NSURL fileURLWithPath:path];
NSURLRequest *req=[NSURLRequest requestWithURL:url];
[menuWeb loadRequest:req];
So what should i do now?
Use HTML instead, it's the only way you're going to get the control you want.
http://cutesoft.net/example/editRTF.aspx
This page is a WYSIWYG HTML generator. It generates extremely clean HTML (*), which I can then save and insert in my project. I can then modify this HTML file from within Xcode. All very nice!
(*) provided you use it right... flip between the normal view, HTML view and final view -- don't make it export into the second text box otherwise everything comes out in an impenetrable chunk.

Open PowerPoint in Iphone/Ipad and display it in my application

I'm trying to write application which will be able to display MS Word docs, MS PowerPoint presentations(ppt). Is there some kind of support for those formats. I know that mail application can open PowerPoint.
If there is no support for it what approach should i take ?
Thanks in advance.
For opening anything (PDF, Pages, Word, Numbers, Excel, Images etc) that the Mail.app or Safari can open, you usually use the UIWebView.
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0F, 0.0F, 320.0F, 480.0F)];
NSURL *pdfURL = [NSURL URLWithString:#"http://www.something.com/myFile.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:pdfURL];
[webView loadRequest:request];
[self.view addSubview:webView];
[webView release];
More info here: http://developer.apple.com/iphone/library/qa/qa2008/qa1630.html
iPhone 2.2.1 supports:
* Excel (.xls)
* Keynote (.key.zip)
* Numbers (.numbers.zip)
* Pages (.pages.zip)
* PDF (.pdf)
* Powerpoint (.ppt)
* Word (.doc)
iPhone 3.0 (the min version required to get into App store today?) adds support to:
* Rich Text Format (.rtf)
* Rich Text Format Directory (.rtfd.zip)
* Keynote '09 (.key)
* Numbers '09 (.numbers) Pages '09 (.pages)
That's relatively easy. UIWebView is able to load office documents.
All you have to do is get a URL to your file (this can be anywhere--the app bundle, the documents directory, the internet, etc.), and have UIWebView load it with -loadRequest
You can use UIWebView to display documents.
Or There are two ways to preview documents: one is to use UIDocumentInteractionController's preview API, the other is directly use QLPreviewController.
Check this link from Apple for more details and source code-
https://developer.apple.com/library/ios/samplecode/DocInteraction/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010052-Intro-DontLinkElementID_2