Please choose a menu option

RSS feed? News:

09 Sep 10 PDF Java Ebook Solution The latest version of PJES is released. Smaller file sizes and quicker turnaround. More...

04 Sep 10 PDF blog Our Java PDF blog has been updated with previous articles, categories and search functions. There's a lot of information there.Try it...

19 Aug 10 Version 4.36 build 60 released JPedal can now read PDF's aloud using the Freetts library, improvements to signing and mouse functions, enhancements to Font and Javascript engines. More Info...

29 Jul 10 JPedal Java ME Viewer Now released and available under an LGPL licence More Info...

12 Jul 10 Version 4.30 build 16 released Enhanced Print dialog, Control via Javascript and Applet enhancements Read More ...

10 Jun 10 Version 4.21 build 56 released Major speed improvements to viewer and general parsing speed. Read More ...

10 Jun 10 JBig 2 image decoder Version 2 released Major Upgrade to JBig2 image decoder - 3-5 times faster. Read More ...

03 Jun 10 Version 4.20 build 21 released Major Upgrade to TrueType font engine supporting Chinese fonts, speed improvements. Read More ...

22 Apr 10 EBook reader encryption Pjes now handles encrypted PDFs - upload an Encrypted PDF, and everyone will need the password to open it.
Ebook reader...

19 Mar 10 Version 4.10 build 16 released First implementation of JPedal in JavaME, support for linearization of PDFs, Coons and Tensor shading support.Read More ...

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.

adding PDF support

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.

adding PDF support

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

 


PDF viewer