hyperlink not working in a pdf in a UIWebView - ios

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"

Related

Make app act as a Server

I'm using CocoaHTTPServer, and I'm able to start the server. In my resources folder, I added a file called "index.html", and here is something that made me confused.
I can get the path of the index file by
[mainbundle
pathForResource:#"index" ofType:#"html"]
but it gave me the path as
/Users/Library/Application%20Support/iPhone%20Simulator/7.0.3/Applications/.
Is there any way to make the path become a web-url like
http://127.0.0.1:56000/user/library/.../index.html" to load it on an
UIWebView.
I want to get the file path like the format above because I want to
catch when the UIWebView request to it and when will the app
response.
Is there any way for me to achieve it??
Thanks in advance.
You can load a resource into a UIWebView like this
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html" inDirectory:#"www"]];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
For catching the requests of a UIWebView please check UIWebViewDelegate protocol here. You can play around with following method for example webView:shouldStartLoadWithRequest:navigationType:

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