We have an "application" consisting of a large number of PDF files that link to each other.
Some of the PDF files have links that must be a web URL when running on a PC (or a Mac) but need to open a specific application when running on an iPad.
When not on the iPad, the links look like "http://10.85.1.102".
When on the iPad, they look like "netcam4://2" - which opens the NetCam4 application with camera 2 selected.
NOTE: this is already working but we have to create two versions of the PDF and it would be much better to have only one.
Is there a way using JavaScript (or ActionScript or whatever) for the PDF to determine in which OS it is being displayed and modify the link appropriately?
We don't care if this decision is made when loading the PDF or when the link is clicked.
By the way, so far we have found that GoodReader on the iPad is the only PDF viewer that will properly follow links - including those to the NetCam4 app.
Not really. PDF is generally run through a browser plugin and shouldn't have script running inside of it.
On the other hand, if you are serving these files up over http, you might be able to modify the contents of the PDF based on how they are compressed and what language you have on the server. PHP has PDFLib, for example, as well as Zend_PDF
Related
Good day,
I have a system that renders large amount of data through pdf ( 30mb + ). Now I want the user to view pdf first so he can either download it or just print it right away. as of the moment I am forcing the user to download the file since open( 'datauri here' ) wont work with larger files.. the problem with downloading is that files are multiplying and consumes space over time and also its not necessary for me to download all files that that they want to print right away.
I need a functionality that is similar to chrome's preview when using windows.print
can you please suggest any ideas or other things to do this?
I am currently using javascript library to create pdf (pdfmake). I am also using chrome as my main browser
You would have to make sure that the PDF is optimized for fast web view, and that your server is using the byteserving protocol for serving the file.
If that is the case, a useful PDF viewer (such as the web browser component provided by Acrobat/Reader) understands this protocol and requests (after the first page plus overhead of the PDF) only the data for the pages which are to be displayed.
A quick search did, however, not reveal whether the Chrome PDF viewing component is smart enough to understand the byteserving protocol.
My chrome packaged app contains a PDF, and I would like to let the user view it. If I open it in the current frame I get the error "Chrome PDF Viewer is not Allowed".
Frankly, the chrome PDF viewer is pretty awful, so I'd rather let the user view it in their PDF viewer of choice anyway. If I disable the chrome PDF plugin (just as an experiment) and I try to open the PDF using chrome.app.window.open, it "downloads" the PDF, and then the user could open it. But this has two issues:
I can't realistically make the user go to chrome://plugins and do that disable
There isn't any browser window, so the user has no idea the download happened
Any suggestions? Opening PDFs that are embedded in my app is kind of a must-have feature for this app.
I've looked at this extensively, and have come to the conclusion that there's no way to get a Chrome App to open a PDF that's local. I, too, have tried data URIs.
I don't think the issue is the PDF support in the window, as it's still Chrome, or the size of the PDFs. Rather, I think it's just an engineering problem, one that might get solved someday.
As for me, I build the PDF in my Chrome App. Since I can't display it, and there's no server to upload it to, I write it to a file of the user's choosing and let the user deal with it on his/her own.
I've got this working, but whether it is a solution for you depends a lot on your use case. The solution has three parts:
Use pdfjs to do the actual rendering.
To get this running in a packaged app, you'd need to do some violence to the internationalization support. And even after you do that, you'll find that some PDFs refuse to load for no apparent reason whatsoever. So don't bother trying to make pdfjs work in a packaged app. Just:
Put your entire app into a <webview> with a persist partition, and use a HTML5 cache manifest to get all your files available for offline viewing.
Yeah, yeah, I know that cache manifests are not cool anymore. But if you can list all your files for use in a packaged app, then you are doing the one case where cache manifests actually work great.
Then use a packaged app to distribute a tiny wrapper around your page with the webview in it.
You'll also get the benefit that you don't have to rewrite your app to live within the draconian packaged app rules (eval, sync xhr, 2GB limit, etc.).
You can see a working example at m.kaon.com/c/ka (visit with Chrome to get the desktop app; if you visit that with Firefox, you'll get access to a hosted app that is using the same tricks). PDFs are down in the bottom "Why Choose Kaon" section.
I'm working on a web application that needs to have a link which opens a documents folder from a file server. The folder can be opened either in a new browser tab or new window, or using the computer's default file browser program (i.e. Windows Explorer). This javascript should do the trick:
window.open('file://///fileserver.companyname/public/Documents/','_blank);
and this html should also work:
Open Documents
but these both only work in Internet Explorer, and our users always use Firefox and Chrome. Apparently the default security settings for Firefox and Chrome don't let you open a "file://" when the request is called from an "http://" website.
I've seen several references to this page: Links to local pages do not work which describes why you can't open files from webpages using Firefox and offers a few workarounds. Unfortunately, it only offers two options: install a plug-in on each browser instance, or create a user preferences file for each browser instance. Neither of these options are acceptable because we have too many users. The company I work for is not willing to apply anything to each machine which needs to access this link. Aside from that, I tried both plug-ins and the preferences file anyway, and the only one that worked for me was the IE Tab plug-in. I think the reason LocalLinks didn't work is because I'm trying to open a folder, not a file.
This stackoverflow question described similar options for Chrome: Can Google Chrome open local links? but again, the LocalLinks plug-in didn't work for me and plug-ins aren't acceptable anyway.
I also found a website that suggested to use a command line argument top open files in Chrome (http://www.askyb.com/chrome/open-local-file-in-google-chrome/) and one that showed how to apply the argument automatically (https://askubuntu.com/questions/160245/making-google-chrome-option-allow-file-access-from-files-permanent), but if I read it correctly it still involves applying changes to every computer accessing our website.
Is there any way to open a file folder in both Firefox and Chrome entirely programmatically i.e. within my web application C# or Javascript code without installing a plug-in or adding a preferences file to individual computers? I cannot alter any of these business requirements.
Sidenote: We are using C# with MVC 4. I would prefer to open the folder using a Controller Action in C# (because I'd like to create the folder before opening it if it doesn't exist yet), but javascript or html on the client side is acceptable. For Internet Explorer, I can create that javascript in the C# code by wrapping it in the JavaScript( ... ) function built into MVC C# Controllers. When testing IE Tabs in Firefox and Chrome, I had to define it as an href link, not a function that opens a window, or IE Tabs wouldn't recognize it as a link. But neither of these were acceptable workarounds for our business needs.
The request was dropped before I could come up with a feasible solution, but in case anyone else is still struggling with this problem I will describe workaround that would not require any workstation customization.
They don't technically need to use the built-in file explorer to open a folder. Instead, a creative way to display the information the business wanted without breaking any browser security rules would be to iterate though the files without opening the file explorer and then display a list of folders/files in a browser window.
Using Directory.EnumerateDirectories(filepath) and Directory.EnumerateFiles(filepath) you can get a list of folders and files to display. When the user clicks one of the folders, call these methods again to get the next level of folders and filenames. When the user clicks a file, download/open it. These methods return the folder and file names as lists of strings, so you would just need to render the lists with custom icons in the browser. (The methods are from C#'s System.IO library.)
here is the simple html code:
<input type="file" webkitdirectory>
but the problem with this code is that it works only on google!
I am writing a page (html, javascript) that is going to be used absolutely for mobile devices.
This page is going to serve some files (typeof: pdf, doc, docx and many others) that browser doesn't recognize. How can I force browser to give the option of saving file and open it with the appropriate installed app?
I tried _blank but nothing, it opens the page and ... raw data appear (not even a new tab starts).
It sounds like you need to make sure the web server is serving the correct mime-type for your content. For uncommon or forced-download types, it can be served as application/octet-stream.
We have a file handling ASP.Net web control used in intranet web applications, that currently uses ActiveX to handle file check-outs, and check-ins. Works fine, in IE&Win.
But now we are trying to get rid of ActiveX & IE only behavior...
If a file is checked out, it is copied to file share, with access right limited to the checking-out user.
Using a hidden iframe, and setting the src of the iframe to something like "file:////file_share/dictionary/users_stuff/someDoc.doc", an open/download dialog is shown, so the user can open and edit the shared file in Word, Excel, etc directly from the file share.
Works fine for file types browsers can't handle themselves.
But for file types like txt, images, html the browser simply loads the file to the iframe, or opens the file, if the user is given a link. And the user can't edit the file without manually launching the appropriate application and copying the url. Showing the users a "Copy this url to your preferred application, and try to edit it" would not be really user friendly...
My question is: is it possible to get the browser (without ActiveX, IE...) to pass the link to the OS, or show a "What do you want to do with this file" dialog of some sort?
If not, what and how could be achieved?
The closest I could come up with is this thread:
https://stackoverflow.com/a/1394725/1195927
#Red says no (and the original poster agrees) BUT #Daan seems to have a solution.
I have not tested, so YMMV.
If a javascript/html solution is not found, I may have an ugly hack for you . . .
See my post here: Launching a Downloadable Link