How to open and view .xlsx files in iOS - ios

I can download documents which can be of types .pdf,.xlsx,.jpeg,.tiff etc from an API. If I use UIWebView it doesnot support .xlsx and .msg files.
How can I view these files.
Can anyone help me ?

You can use the QLPreviewController to display all of these types of files.
A Quick Look preview controller can display previews for the following items:
iWork documents
Microsoft Office documents (Office ‘97 and newer)
Rich Text Format (RTF) documents
PDF files
Images
Text files whose uniform type identifier (UTI) conforms to the public.text type (see Uniform Type Identifiers Reference)
Comma-separated value (csv) files

use this code u will get satisfied
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:file type];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
try this it will help you to make zimmicks with any type of file

Related

how to save existing pdf file in NSDocumentDirectory in ios

I have one pdf file and I want to save that file using NSDocumentDirectory and retrieve it.how do i convert pdf file into NSData so that I can save. Please help me. Thanks in advance.
Brad,
Welcome to Stack Overflow.
This is not a site where people give you solutions to your problems "out of whole cloth". You need to show what you have attempted, and the specific places where you are stuck.
You say you "have one pdf file". Is it a file on disk somewhere, in memory, or what? If it's already on disk then you can use the file manager to copy it to the documents directory. Take a look in the Xcode docs under NSFileManager and read the class reference. There are tons of useful methods for creating and copying files.
You say "..how do i convert pdf file into NSData so that I can save." Erm, if it's a file, why do you need to convert it to NSData in order to save it? It's already a file.
NSData has methods for creating a data object with the contents of a file (dataWithContentsOfFile and dataWithContentsOfURL) as well as methods for writing an NSData object to a file (again using a path or an NSURL, like the dataWith... methods)
As you said you have PDF file so i guess it will be a ready file.
Now in that case you don't need to put it in document directory. Just put it into your resources folder where you placed images & other files.
After that to read that pdf file Simply do this:
UIWebView *myweb = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
myweb.scalesPageToFit = YES;
NSString *path = [[NSBundle mainBundle] pathForResource:#"myPDF" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[myweb loadRequest:request];
[self.view addSubview:myweb];
Hope it will work for you.

PDF Text Extraction in iOS [duplicate]

I'm displaying locally stored pdf in my iPad application. Here's the code:
NSString *path = [[NSBundle mainBundle] pathForResource:#"About Downloads" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[pdfWebView loadRequest:request];
Now, by default, you can't copy text or images from the PDF which is rendered by the UIWebView. Is there a way to let users copy text and/or images out of pdf?
I'm not familiar with CATitledLayer, so i'm just wondering if it can help in this case?
There's no simple answer to this. PDF's are nested dictionaries composed of more dictionaries & arrays. You'll have to dig into CGPDFDocument. Voyeur is an excellent tool to use while digging around in PDF's. Reader is a good suggested starting point for rendering PDF's.
To get at the text in a PDF Document, I use PDF Kitten (https://github.com/KurtCode/PDFKitten). It works quite well, but as the author notes, is incomplete and does not support all font types.

Localization XCode 4.5 + language-specific PDF loaded in main UIWebView / IOS

I'm working on a bilingual simple IOS App: a PDF file is loaded in a UIWebView with the method described here:
Loading Local PDF File Into WebView
In XCode, using the "Localization" feature, I added a second language (French). The MainStoryboard contains 2 "sub" storyboards, one for English, and one for French.
In the MainStoryboard (English), I inserted a UIWebview --> connect that view to the MainViewController.h --> add the code for inserting the English PDF file in the MainViewController.m:
NSString *path = [[NSBundle mainBundle] pathForResource:#"EnglishBook" ofType:#"pdf" inDirectory:#"PDFBooks"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_UIWebViewBook loadRequest:request];
[_UIWebViewBook setScalesPageToFit:YES];
The English version runs well.
But... where to put the French PDF file ?
Is there a way to target a language-specific PDF file ?
Could "pathForResource:#" be "language" sensitive ?
Thanks for your help !
NSString *path = [[NSBundle mainBundle] pathForResource:#"Book" ofType:#"pdf" inDirectory:#"PDFBooks"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_UIWebViewBook loadRequest:request];
[_UIWebViewBook setScalesPageToFit:YES];
Make the request for a single book, then in your project folder make a subfolder en.lproj and fr.lproj add the English version French version respectively and drag both into your Xcode project.
They will both appear, under en.lproj and fr.lproj, then depending on the device localisation, the correct one should load.
To Clarify. In Finder set up this directory structure:
When you then drag MyBook.txt (pdf in your case) to Xcode, it will look like:
Then when you call for MyBook.txt the device will automatically chose which version to grab, depending on the devices international language settings (Settings-General-International-Language).
You might also want to look into UIDocumentInteractionController for documents.

show .key(keynote) file in iphone

I am given some keynote files .
I have to put along with an app .
when I open any app it should show that keynote presentation in the app .
my questions are ,
Does ios supports keynote presentation?
if yes, how to show them ?
However I checked this out ...
but.. not working
http://developer.apple.com/library/ios/#qa/qa1630/_index.html
iWork '09 documents do not use a package format and must not be ZIP compressed.
To display supported documents in a UIWebView, create an NSURL as a file URL with the path to the document. Listing 1 demonstrates a method that uses a UIWebView to load a document from your application bundle.
Listing 1 Loading a document into a UIWebView.
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
// Calling -loadDocument:inView:
[self loadDocument:#"mydocument.rtfd.zip" inView:self.myWebview];
You can open the keynote file in a UIWEBVIEW as a local bundled file or sitting on a server as well.
NSString *urlAddress = [[NSBundle mainBundle] pathForResource:#"test" ofType:#"key"];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
you can view Excel (.xls), Keynote(.key.zip), numbers (.numbers.zip), pages (.pages.zip), PDF(.pdf), Powerpoint (.ppt), Word (.doc), Rich text format (.rtf), Rich text format Directory (.rtf.zip), Keynote '09(.key), numbers '09 (.numbers) and pages '09(.pages)
Alternatively, or indeed alongside the preview functionality, you can give the user the option to open the keynote using any able and installed applications externally.There's a good answer to a question requesting this feature here: How to use "open in..." feature to iOS app?

Reading text and images from a pdf document in iOS

I'm displaying locally stored pdf in my iPad application. Here's the code:
NSString *path = [[NSBundle mainBundle] pathForResource:#"About Downloads" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[pdfWebView loadRequest:request];
Now, by default, you can't copy text or images from the PDF which is rendered by the UIWebView. Is there a way to let users copy text and/or images out of pdf?
I'm not familiar with CATitledLayer, so i'm just wondering if it can help in this case?
There's no simple answer to this. PDF's are nested dictionaries composed of more dictionaries & arrays. You'll have to dig into CGPDFDocument. Voyeur is an excellent tool to use while digging around in PDF's. Reader is a good suggested starting point for rendering PDF's.
To get at the text in a PDF Document, I use PDF Kitten (https://github.com/KurtCode/PDFKitten). It works quite well, but as the author notes, is incomplete and does not support all font types.

Resources