What's the best way for determining whether the user's browser can view PDF files?
Ideally, it shouldn't matter on the browser or the operating system.
Is there a specific way of doing it in ASP.NET, or would the answer be just JavaScript?
Neither, none, don't try.
Re dawnerd: Plug-in detection is not the right answer. I do not have a PDF plugin installed in my browser (Firefox on Ubuntu), yet I am able to view PDF files using the operating system's document viewer (which is not Acrobat Reader).
Today, any operating system that can run a web browser can view PDF files out of the box.
If a specific system does not have a PDF viewer installed and the browser configured to use it, that likely means that either it's a hand-made install of Windows, a very trimmed down alternate operating system, or something really retro.
It is reasonable to assume that in any of those situation the user will know what a PDF file is and either deliberately choose not to be able to view them or know how to install the required software.
If I am deluding myself, I would love to have it explained to me in which way I am wrong.
A quick google search found this. Useful for all kinds of plugins.
There are users that choose not to open PDF's in the browser and disable the plugin (this allows the file to be opened in the native application external of the browser window). It is better to let the user know that software is required to open something (whether it be PDF or not) than try to detect whether the plugin is available.
Another problem with detection is that what you need to look for changes from version to version (for example, see: "PDF.PdfCtrl.*" vs "AcroPDF.PDF.*" for the Adobe PDF viewer) and different browser implementations (the previously mentioned strings are used in IE for example, while Firefox uses a totally different manner of detection. Then we need to think of Opera and Safari and ???). Also, there are different vendors (think Foxit and Ghostscript, though I am not sure if they supply a plugin for the browser) where there may be differences in detecting the plugin.
For a script written in 2008 and some more information about the caveats see Detecting plugins in Internet Explorer (and a few hints for all the others).
After initially ignoring the advise on this page the architect went ahead with Acrobat detection, causing an inevitable support nightmare.
As ddaa mentions not all the scenarios can be accurately captured with Plug-in detection. Some users, for example, may choose to view PDF files with FoxIt Reader rather than acrobat. Some user's browsers don't flag that they are Acrobat ready, and certainly not always in the same way.
A better solution would have been to give the user a choice on how they'd like to view the relevant document. Personally, I don't like to have any website rely on a plug-in - it spoils the beauty of the web.
Related
Is there a way to get a screen capture (of the client screen) in meteor? I don't care whether it's available (once captured) on the client or the server - either is fine.
I saw something similar to this but it appeared to only work for a browser window. I'm looking for a screen capture of the client screen no matter what is active - even if there's no browser open - just as if the user hit the "PrntScrn" key then pasted into a jpg file and saved it somewhere.
One cannot do such things (calling unapproved OS functions) from code that runs inside of a web browser.
This is a deliberate design decision for web browsers, as one doesn't want scripts from the broader internet running arbitrary code on your computer.
Internet Explorer used to (not sure if still) provide "hooks" for Windows Update that involved an Active-X control that interacted with the OS.
They MADE the OS (Microsoft) so it was their prerogative, but it undoubtedly lead to some exploits...
You can use html2canvas for generating the screenshot. There is a meter package too for the same on atmospherejs. You can find the docs and examples here
Alternative is to use PhantomJS to do this job.
Chrome is on the verge of definitly break compatability with NPAPI, and IE breaking with ActiveX the future of Java Applets is dark. Currenty we actively use a secure applet for out client organizations that enables their users to upload a bunch of files from their file system to our servers with the click of a button. The applet has full access to any configured drive, including network drives.
With the imminent death of the applet this functionality is going to be lost if we don't find an alternative. I have already tried to explore different solutions, including the chrome FileSystem API but that is currently only available for Chrome (http://caniuse.com/#feat=filesystem) and has limited access.
Does anybody know about an alternative to keep supporting the much appreciated functionality? Unfortunately we are obligated to support all browser down to IE8.
I've written a post about this here.
Once Google Chrome was the first to announce that they won’t be supporting NPAPI anymore, they were also the first to provide a new architecture in order to rewrite your code to work on their browser. You can take a look on Native Messaging, which “can exchange messages with native applications using an API that is similar to the other message passing APIs”. The problem is that this approach only works on Chrome, is not something that you can adapt to other browsers.
A more useful approach is FireBreath, a browser plugin in a post NPAPI world. Check the words below from one buddy of the project:
“FireBreath 2 will allow you to write a plugin that works in NPAPI, ActiveX, or through Native Messaging; it’s getting close to ready to go into beta. It doesn’t have any kind of real drawing support, but would work for what you describe. The install process is a bit of a pain, but it works. The FireWyrm protocol that the native messaging component uses could be used with any connection that allows passing text data; it should be possible to make it work with js-ctypes on firefox or plausibly WEB-RTC or even CORS AJAX in some way. For now the only thing we needed to solve was Chrome, but we did it in a way that should be pretty portable to other technologies.”
In light of the answer provided by Uly Marins I have researched the options suggested. Unfortunately these options weren't viable for our application, because the mayority of our users do not have sufficient rights to install third party plugins. Additionally the API is still in Beta which won't do any good in a stable production environment.
The main problem we wanted to solve was the abbility to delete files from the accessed folders. It seemed like one of the mayor goals of the removal of the NPAPI support was exactly to prevent this kind of possibility. Therefore we needed to reduce our goals to a simple solution that was still acceptable for our users, with the additional training on how to clear the selected folder manually (because most of our users are almost computer illiterate and needed to access network folders).
Long answer short. The requested solution is just not possible anymore and had to be replaced by a simpler solution and additional training.
I am using QDesktopServices::openUrl(url); to open a url.
How can I close that through user defined code?
You are opening your URL in a browser window, on which user code doesn't have any control.
So basically you cannot close the browser.
A workaround could be that you write a script and detect if a browser is opened on the system, if yes you can close the browser by terminating that process. But I do not recommend this method as it has many security and standard compliance issues on some platforms.
EDIT:
You do not need to create your own browser, just use Qt Webkit to render the opened URL within your own window.
I'm afraid I don't believe you can close a URL via Qt code, with QDesktopServices.
The user could have configured their operating system to open URLs with any number of different browsers, and I don't see how it would be practical for Qt to be coded to know how to close every different type of browser porgramatically, on every different platform they support.
Edit
An alternative is to put a browser widget into your application. Then you'll have control over that. Qt provides some pretty powerful tools for is. See the Qt WebKit documentation.
Is there some kind of light-weight (non-Adobe) control I could use to view and print PDF documents on a web form?
I use Foxit. Lightweight - loads faster than Adobe.
ABCPdf is a free PDF generator for ASP.NET; all you have to do is link back to their site if you use it.
http://www.websupergoo.com/abcpdf-1.htm
Flashpaper, it is platform independant.
The reason I suggest this is that you can embed PDF viewing right in any web-browser via this Flash Plugin (and print), but never have to have PDF viewing software installed or configured to work with the web browser.
Edit: As per the comment, new Flashpaper versions have been discontinued. Flashpaper will continue to be available for sale though. (see link in comment). I have used it for several years and haven't found much of a need for new features, but your case may differ. Try it out.
Foxit Reader is more lightweight than the Adobe Reader.
For displaying a PDF, you could use PDF Me Not.
I'm not sure if you mean generating a PDF of a form submission, though. If this is what you meant, there are PDF libraries for just about every language (such as FPDF for PHP).
For the first case, there's also AlivePDF which is open source.
Aspose.com can do some pretty nifty stuff for .NET and Java
phpLiveDocx and LiveDocx are completely free and can be used to merge data (for example, from a web form) with a template from MS Word or Open Office on the server.
phpLiveDocx runs on Linux, Windows and Mac.
LiveDocx runs on Windows.
Learn more at:
http://www.phplivedocx.org/articles/brief-introduction-to-phplivedocx/
http://www.livedocx.com
Is there any reasonable method to allow users of a webapp to download large files? I'm looking for something other than the browser's built-in download dialog - the requirements are that the user initiates the download from the browser and then some other application takes over, downloads the file in background and doesn't exit when the browser is closed. It might possibly work over http, ftp or even bittorrent. Platform independence would be a nice thing to have but I'm mostly concerned with Windows.
This might be a suitable use for BitTorrent. It works using a separate program (in most browsers), and will still run after the browser is closed. Not a perfect match, but meets most of your demands.
Maybe BITS is something for you?
Background Intelligent Transfer
Service Purpose
Background Intelligent Transfer
Service (BITS) transfers files
(downloads or uploads) between a
client and server and provides
progress information related to the
transfers. You can also download files
from a peer.
Where Applicable
Use BITS for applications that need
to:
Asynchronously transfer files in the
foreground or background. Preserve
the responsiveness of other network
applications. Automatically resume
file transfers after network
disconnects and computer restarts.
Developer Audience
BITS is designed for C and C++
developers.
Windows only
Try freeDownloadManager. It does integrate with IE and Firefox.
Take a look at this:
http://msdn.microsoft.com/en-us/library/aa753618(VS.85).aspx
It´s only for IE though.
Another way is to write a BandObject for IE, which hooks up on all links and starts your application.
http://www.codeproject.com/KB/shell/dotnetbandobjects.aspx
Depending on how large the files are, pretty much all web-browsers all have built-in download managers.. Just put a link to the file, and the browser will take over when the user clicks.. You could simply recommend people install a download manager before downloading the file, linking to a recommended free client for Windows/Linux/OS X.
Depending on how large the files are, Bittorrent could be an option. You would offer a .torrent file, when people open them in a separate download-client, which is seperate from the browser.
There are drawbacks, mainly depending on your intended audience:
Bittorrent is rarely allowed on corporate or school networks
it can be difficult to use (as it's a new concept to lots of people).. for example, if someone doesn't have a torrent client installed, they get a tiny file they cannot open, which can be confusing
problems with NAT/port-forwarding/firewalls are quite common
You have to use run a torrent tracker, and seed the file
...but, there are also benefits - mainly reduced bandwidth-usage on the server, as people download also seed the file.