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

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

Related

Open PDF file contained in the URL

I have a link that contains a downloadable pdf file. This link doesn't have its extension as .pdf, its just a normal link. Its a web-service where i pass "PDF" as a parameter that returns me a PDF file. Whenever I open such link on a desktop browser, it directly ask for downloading the pdf. Into my ipad app, i need to display such pdf in a web view. What can be the possible solution?
You should make a url request and load that in to a Webview like this,
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[webView loadRequest:request];
The url is your link to the PDF file and webview is UIWebView object where you can view the PDF.

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

File Formats Supported by UIWebView

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

iPhone app which is only a local HTML file, how?

I have a HTML Ajax website which consists only of one HTML file. How can I create an iPhone App out of it? The HTML file should be stored locally on the iPhone so it functions offline.
UIWebView *htmlView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,380.0)];
[htmlView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"]isDirectory:NO]]];
[self.view addSubview:htmlView];
[htmlView release];
Depending on what level of AJAX you're using, the "CSS Ninja" has a nice tutorial on how to add the proper code your HTML file to make it accessible offline.
You can look at something like PhoneGap or iui.
You will probably want to do at least a tab bar with the webpage in one tab and an "about" or something in the other. Apple has been known to refuse apps that are just a straight up wrapper of a single page.
Finally I found two very good video tutorials which are explaining how to build an "UIWebView for iPhone App"
http://www.youtube.com/watch?v=_ZcND6ZVOYw
http://www.youtube.com/watch?v=EZKSbb40Jp8

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.