UIWebView loadData and iWork Files - iphone

I am attempting to open an iWork 10 Numbers file placed on a Web site into a UIWebView. I tried with the following, and what happens is that the UIWebView loads blank. If I download the file to local the Documents folder and then load it in the UIWebView it then works. I'd like to read an iWork file without downloading them...
FYI, I have no issues with PDF, PPT, DOC, XLS...
Can anyone tell me how to load an iWork file from NSdata to UIWebView?
[webView loadData:receivedData
MIMEType:file.mediaMimetype
textEncodingName:nil
baseURL:[NSURL URLWithString:PATHTOFILE]
];
The tested values for mediaMimetype are:
application/vnd.apple.numbers
application/x-iwork-numbers-sffnumbers

You need to compress iWork file with .zip extension to display in webview.
refer this link for detail:
http://developer.apple.com/library/ios/#qa/qa1630/_index.html

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];

JavaScript along with the HTML file is not running in UIWebView

I have placed the HTML Resource files and java script files with the project files in my iphone application. My objective is to build an application which has UIWebview which loads when we tab on the app icon. The UIWebView should actually load the local html content that I have in the resource folder. I can see the HTMl content in the webview but its not running the Javascript..
Checkout stringByEvaluatingJavaScriptFromString: in the
UIWebView Class Reference
Her the actual problem comes with adding the files(javascript and css) in the project. while adding files following option should be clicked that showed in the following image.

How to make hyperlinks in pdf displayed in UIWebView work

Given a pdf created with pages that includes working imbedded hyperlink, stored as a resource with my app and displayed in a UIWebView, what needs to be done to make the hyperlink work in in the UIWebView.
Scouring the posts here and elsewhere on this subject it appears that a link should just work if you want it to display in Safari. I can't get them to work.
In pages I created the document and created a hyperlink to http://www.excite.com/ for testing purposes. I then exported the document as a pdf. The link works fine when the pdf is displayed in Preview. I then added the pdf to my app resources folder and loaded it into the UIWebView. The link does not work.
The UIWebView was created with IB and I have the Links property checked.
I am loading the pdf with the following code...
NSString *pdfPath =[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:[documents objectAtIndex:documentNumber]];
pdfUrl = [NSURL fileURLWithPath:pdfPath];
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
What more do I need to do?
For now I just would like the link to open in Safari. Eventually I will need to have links that allow me to link to other pdfs in my resource folder and display them in the same UIWebView. To do this I understand I will need to implement a UIWebViewDelegate.
Thanks,
John

Is that possible to cache UIWebView in iPhone?

I was using NYTimes iPhone application, I become bit curious when I notice that it cache UIwebview even though I didn't open that article.Does anyone have idea how to do that?
How NYTimes iPhone application doing offline reading?
Any help greatly appreciated.
Thanks,
Amit
I wrote the NYTimes app. Here are some details that you could have gotten by looking inside the app bundle.
I download the HTML for the articles, strip out whatever unsupported HTML and JS crud the producers stuffed in it and cache it in the backing store.
The article content is contained in a series of P tags (HTML fragment). I stuff that into a special HTML skeleton page that ships with the app. The static wrapper page also contains CSS and JS used to properly display the article and lazily load the images.
The image loading is really cool. The web view is notified when the images are ready. layout is not affected because I already know the sizes of the missing images.
You can use UIWebView to load html files stored locally on the iPhone.
NYTimes app is probably caching html and images in local storage.
Search google for "UIWebView local" and you get several useful hits.
I tried it out and it works great:
First, create a "view based application" and add a UIWebView to the NIB.
Second, add this code to your UIViewController code:
- (void)viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"];
NSURL *url = [NSURL fileURLWithPath:path isDirectory:NO];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[super viewDidLoad];
}
Third, add a file called "index.html" to your "Resources" folder in xcode and it will be displayed.
UPDATE:
Indeed, the complicated part of this is downloading the images and stylesheets for the webpage. Doing this server side is easy with Simple HTML Parser (and PHP). Just package everything in a zip and download to your iPhone.
Alternatively, you could do it locally with a C/C++/OBJC HTML parser (libxml2.2 is available on iOS). See this SO question Parsing HTML on the iPhone.
It's going to a bit of a project, so good luck.