How to run PDF Viewer in a browser
Technology moves on as ever at a breakneck pace. One of the advantages of using Java in the early days was that it provided a safe and platform-independent way to provide graphical program functionality, both on the desktop and also in the browser via applet technology. As with Flash, though, the complex security issues surrounding applets eventually proved too difficult for browser manufacturers and developers to keep up with and they became obsolete.
For some time now many of our clients using the BFO PDF Viewer have run it exclusively on the desktop or via Java Web Start, which mandates a Java Virtual Machine on the client machine to run it in, and having to manage different versions of both the PDF Viewer and the JVM deployed around the enterprise creates additional work for system administrators. In this article we look at how you can use Webswing to run a set of instances of the PDF Viewer application on a server, and have clients use the program exclusively via a standard browser, negating all the client software deployment issues and bringing back the advantages of applet technology without the security concerns.
What is Webswing?
Webswing is a product that functions as a web server (or servlet web application) that allows a modern JavaScript-enabled browser to run Java Swing applications on the server and display them in a browser page: specifically, in an HTML canvas. In the JVM on the server, the AWT windowing environment implementation, instead of handling user events and graphics drawing operations with respect to a native display server with a screen and input devices, is replaced with one that delegates these events and graphics operations to a websocket protocol communicating with JavaScript in the browser. Since Swing is built entirely in "lightweight" AWT - there are no operating-system-native components such as buttons, lists, text fields, etc - only the absolute highest level components (windows and canvases) need to be mapped to the HTML canvas in the client's browser.
As such, a Java virtual machine is certainly required on the server, and only certain Java versions and implementations are supported. In addition a windowing environment, even if headless, is also required to manage certain AWT details such as fonts. However the complexity of managing the software installed on just this one machine is massively simplified in comparison to having to manage that for an arbitrary number of client machines which can all use standard modern browsers. In addition to the flexibility of client devices (which can now of course include mobile devices such as smartphones and tablets as well as desktops), given that the server component is 100% Java the server can run a wide choice of operating systems as well.
What does PDF Viewer in the browser look like?
You can explore the look, feel, and functionality of PDF Viewer in the browser via Webswing in our online demo. Essentially it looks exactly the same and has all the same functionality as the desktop version. You can choose to limit the available documents programmatically, or allow your users to open and save their own documents in the own client filesystems.
How can I run PDF Viewer using Webswing?
For the most part it is as easy as following the Webswing installation documentation and adding PDF Viewer as an app. We do have a number of useful tips for deployment however, so if you are planning to do this please get in touch with us and let us know exactly how you want the PDF Viewer to appear to clients, which features should be enabled, and especially whether you plan to deploy the server standalone or inside a servlet container.
Conclusion
You can use Webswing to embed a BFO PDF Viewer into a web page, whether this is is to provide a fully functional PDF manipulator for your intranet, or a specialised PDF viewing component for the world at large that supports many of the most extreme and unusual features of PDF that are unsupported (or not rendered faithfully) by common JavaScript-based PDF viewers such as the in-browser viewers in Firefox and Chrome.