Add PDF viewing with two lines of Java code
This tutorial explains how a java PDF viewer may be added to a Java application.
How to add java PDF viewer to your code
Assuming you have an existing piece of software, adding PDF viewing to your java software couldn't be easier.
First, within your own java code, ensure you have a component to display your PDF file on. If you haven't created one yet, please do so now. Below is a simple JFrame and JLabel I made to demonstrate this functionality.

Next, after you have created your component all you need to do is create a simpleViewer object using the constructor SimpleViewer(Container display, String PreferencesPath) passing in your component as the varible display. If you do not wish to specify a preferences file just pass a null value or an empty string into the constructor.
Once this has been done, just add your component to the user interface and it is done. Our simpleViewer in your software. Below this the simple JFrame and JLabel with the simpleViewer added.

The two lines of code added to the simple JFrame and JLabel at the begining are:
SimpleViewer viewer = new SimpleViewer(rootContainer, null);
viewer.setupViewer();
Now the object has been set up correctly it can be added to your application like any other swing component.
Here is the simple application I made, demonstrating how this can be done.
If you wish to remove some or all of the simpleViewer user interface that is also possible by simply setting the preferences to display the desired components and passing in the path (on the file system or within the jar by adding "jar:" to the start of the path) to this file in the SimpleViewer(Container display, String PreferencesPath) constructor.
Click here to learn how to remove user interface components from our software.
Return to main PDF support section
Click here for the main PDF support area with lots of java examples, PDF tutorials and useful information to get the most out of the JPedal PDF library




