How to Create a Web-Based Viewer in Java
In the following tutorial, we will detail how to create an HTML embed code for a simple web-based document viewer using an API in Java.
Join the DZone community and get the full member experience.Join For Free
A web-based viewer is essentially a basic visual display window for documents you want users to be able to explore on your website or application. Document viewers are a great way to get a quick look at a document without worrying if you have the correct applications to view it on your device. With these tools, customers can simply click on a PDF or Word document on a website and peruse it as they would in its native format.
Web-based or HTML viewers are also known as ‘zero footprint’ viewers as they do not require a separate client install or download, which allows for the viewing of documents within the browser itself. These installations are less of a hassle if you are dealing with just one format on one device, but considering the ever-changing array of file types and machines that we utilize every day, they have become inefficient and cumbersome. In addition to the absence of software installation, the ‘zero footprint’ name also signifies that the viewer does not store data on the user’s device, and there are no storage parameters that need to be met.
In the following tutorial, we will detail how to create an HTML embed code for a simple web-based document viewer using an API in Java. This tool provides support for all Microsoft Office document formats, as well as PDF.
To get started, we will first install the Maven package by adding a reference to the jitpack repository:
Next, we will add a reference to the dependency:
Following the installation, we will add our imports to the top of the controller and call the create viewer function:
To ensure the smoothest outcome to the operation, the following parameters should be included:
- API Key — your personal API key can be retrieved from the Cloudmersive website by registering for a free account; this will give you access to 800 calls/month.
- Input File — the file you wish to create the embed code for.
- Width (optional) — width of the output viewer in pixels.
- Height (optional) — height of the output viewer in pixels.
Armed with your newly created HTML embed code, you can enable easier document display for users. If you have other documents you'd like to design a viewer for, simply input the new file into the code and repeat the process.
Opinions expressed by DZone contributors are their own.