Reading text and images from a pdf document in iOS - 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.

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.

hyperlink not working in a pdf in a UIWebView

I have text file (instructions.docx) with a hyperlink in it - I convert it to a pdf (instructions.pdf) and use it in a UIWebView as follows:
NSString *path = [[NSBundle mainBundle] pathForResource:#"Instructions" ofType:#"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
[_webView setScalesPageToFit:YES];
All works fine except the hyperlink does not work - shows blue - but tapping it does nothing.
Am I going about this the wrong way - or am I missing something?
I'm not sure, but you can try this line of code:
[_webView setDataDetectorTypes:UIDataDetectorTypeLink];
Otherwise, you can try Reader library by vfr. PDF embedded links work in it.
Also you may want to take a look at this question.
I had a similar problem. Turns out the links in the PDF weren't hyperlinks. They were just typed in (even though they were blue and looked like real hyperlinks).
Resolved the issue by:
Manually adding hyperlinks
Checked Word to PDF conversion allowed for "Best for electronic distribution and accessibility"

How to open and view .xlsx files in 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

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.

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?

Resources