Making JPedal your default PDF viewer in Ubuntu

2 min read

Once java has been installed on your machine (see Installing Java in Ubuntu article), you can setup JPedal. How you setup your directory structure is up to yourself. I placed the JPedal jar file and associated libraries in home/feq/programs/jpedal (feq is a name I made up on my computer). Provided you place the correct paths in the shell script, it doesn’t matter where these files go.

Creating the shell script

To run JPedal you need to setup a shell script. Again there are plenty of different ways to do this. I used the text editor supplied with Ubuntu (Applications/Accessories/Text Editor). I named the file and saved it to my home/feq directory. The file should look something like:


java -Xmx512m -Dorg.jpedal.startWindowSize=1000×1200 -cp /home/feq/programs/jpedal/iText215.jar:/home/feq/programs/jpedal/bcprov-jdk14-119.jar:
org/jpedal/examples/simpleviewer/SimpleViewer “$1”

Lets examine this:

# This is preamble that tells linux to execute the script using the Bourne shell.

java calls the Java interpreter.

-Xmx512m tells the computer to allocate 512Mb of memory to Java (optional)

-Dorg.jpedal.startWindowSize=1000×1200tells Java to start JPedal in a window 1000 pixels wide by 1200 pixels high. (optional)

-cp …. tells java what classes to load and the full path of the file. In this instance I have loaded:
The iText library (iText215.jar) – this adds page a PageTools menu to JPedal allowing PDF manipulation commands such as page insertion, deletion and stamping.
The Bouncy Castle Cryptography library (bcprov-jdk14-119.jar) – Provides a cryptography library for Java.
The Java Advanced Imaging (JAI) libraries (jai_core.jar; jai_codec.jar) used for high performance image manipulation. You need these for our alternative GUI PageTurn and PageFlow modes.
The JPedal library (jpedal.jar) – contains the code to run our PDF viewer.

All these libraries need to be separated by a colon. Do NOT put a space in this line to make it easier to read – the shell interpreter reads whitespace as a command.

org/jpedal/examples/simpleviewer/SimpleViewer tells JPedal to run its SimpleViewer example program (loads a single PDF file). Substituting ‘SimpleViewer’ with ‘MultiViewer’ for the last term starts our MultiViewer example program (loads multiple PDF files into memory).

“$1” allows us to open a pdf file by double clicking the file name. If you don’t put quotes around this term, the name of the file is terminated at the first space it encounters.

Once the script is saved, it needs to be permissioned so it can be run as an executable. To do this, use chmod a+x, which gives the script permission to be executed by all.

Changing the Default PDF viewer


This is extremely easy in Ubuntu. Simply find any pdf file in a file manager and right click on the file name. Click the ‘Open with other Application’ choice. Make sure the check box at the bottom of the dialog (remember this application for ‘PDF document files’) is checked. Then choose the ‘Use a custom command’ option. Now navigate to the shell script created above and click the open button.

That’s it. When you click a PDF file name in future the shell script you created will run and call JPedal to display your PDF file.

Tricks for new players

Can you spot the difference between:

java -Xmx512m /home/feq/programs/jpedal/examples/simpleviewer/SimpleViewer


java -Xmx512m /home/feq/programs/jpedal/examples/simpleviewer/SimpleViewer

Well, neither could I. It turns out the first file was written using windows and copied across to the Linux partition. The second example was written in Linux. Example 2 works, example 1 doesn’t. Window uses a carriage return AND line feed to mark the end of a line, Linux uses only a carriage return. When you run a windows script on a linux box, the shell interpreter will see the carriage return + line feed and fail. This took me more time than I care to admit to find and fix.

For more information:

JPedal JVM options
JPedal Example Programs

Leave a Reply

Your email address will not be published. Required fields are marked *