By Mark Stephens
Expert Author
Article Date: 2011-01-21
Once java is installed on your machine (see previous post), 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.
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 SimpleViewer.sh and saved it to my /home/feq directory. The file should look something like:#!/bin/bash
#
java -Xmx512m -Dorg.jpedal.startWindowSize=1000×1200
-cp /home/feq/programs/jpedal/iText215.jar:/home/feq/programs/jpedal/bcprov-jdk14-119.jar:
/home/feq/programs/jpedal/jai_core.jar:/home/feq/programs/jpedal/jai_codec.jar:
/home/feq/programs/jpedal/jpedal.jar org/jpedal/examples/simpleviewer/SimpleViewer "$1″
Lets examine this:
#!/bin/bash
# This is preamble that is used in most shell scripts
java calls the Java interpreter.
-Xmx512m tells the computer to allocate 512Mb of memory to Java (optional)
-Dorg.jpedal.startWindowSize=1000×1200 tells 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)
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)
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.
Don't forget to give your script execute permissions (chmod a+x).
Making JPedal 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
and
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.
Comments