Perl programmer for hire: download my resume (PDF).
John Bokma MexIT
freelance Perl programmer

Installing Apache FOP manually on Lucid Lynx

Monday, July 4, 2011 | 0 comments

Since I had installed Oracle Java installed manually without a single problem I decided to install Apache FOP manually as well. Also because when I tried to install it via sudo apt-get install fop it turned out that Ubuntu didn't see that Java had already been installed, most likely due to a step I hadn't taken after the manual installation of Java. Another advantage of the manual installation turned out to be a newer version of Apache FOP; 1.0 instead of 0.95.

Below follows a HOWTO of how I installed Apache FOP sucessfully on Ubuntu 10.04 LTS.

Downloading Apache FOP

Select the first suggested mirror on Apache FOP Download Mirrors and click on the binaries link in the resulting web page. Next click fop-1.0-bin.tar.gz to download the tarball.

After the download had finished I generated the MD5 digest for the file and verified it with the MD5 digest given on the official site:

cd ~/Downloads
md5sum fop-1.0-bin.tar.gz 
3186f93a314bdcb710bd7cb02d80404c  fop-1.0-bin.tar.gz

Installing Apache FOP

After you have verified the integrity of the downloaded file create a directory to install fop into, unpack the tarball, clean up and create a symbolic link to the latest (and currently only) version as follows:

sudo mkdir /usr/local/fop
cd /usr/local/fop
sudo mv ~/Downloads/fop-1.0-bin.tar.gz .
sudo tar zxvf fop-1.0-bin.tar.gz
sudo rm fop-1.0-bin.tar.gz
sudo ln -s /usr/local/fop/fop-1.0/ latest

Next we have to add a path to the fop bin directory to the PATH variable. Thanks to the symbolic link we can use /usr/local/fop/latest/bin and when a new version of FOP comes out only the symbolic link has to be updated.

Open /etc/environment in an editor, for example use sudo vi /etc/environment, and modify the PATH variable. The file looks on my computer currently as follows:

JAVA_HOME="/usr/local/java/latest"
JRE_HOME="/usr/local/java/latest/jre"
PATH="/usr/local/java/latest/bin:\
/usr/local/fop/latest:\
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

Make very sure that no space follows the back slash or any other character other than a new line for that matter. If you make a mistake in this file you might no longer be able to login. This happened to me once. I fixed this by booting a live CD and editing /etc/environment

You can verify the updated /etc/environment and if Apache FOP got installed correctly as follows:

source /etc/environment 
fop -version
FOP Version 1.0

Note that sourcing /etc/environment is only required once in a terminal and only until you log out and log back in.

Hello World in XSL FO

To test Apache FO, copy the XSL FO snippet that follows to a file hello-world.fo

<?xml version="1.0"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="page">
      <fo:region-body
	      region-name="body"
	      margin-top="0.5in"
	      margin-bottom="1in"
	      margin-left="0.5in"
	      margin-right="0.5in"/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="page">
    <fo:flow flow-name="body">
      <fo:block>
	Hello, World!
      </fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>

and convert it to PDF using:

fop hello-world.fo  hello-world.pdf

You can open the Document Viewer from the command line as follows:

xdg-open hello-world.pdf

Note that if you rerun fop to update the PDF file the Document Viewer will update its view and show the new version.

Apache FOP Related

Also today

Please post a comment | read 0 comments | RSS feed