NAME
XML::ApacheFOP - Access Apache FOP from Perl to create PDF files using XSL-FO.
SYNOPSIS
use XML::ApacheFOP;
my $Fop = XML::ApacheFOP->new();
# create a PDF using a xml/xsl tranformation
$Fop->fop(xml=>"foo.xml", xsl=>"bar.xsl", outfile=>"temp1.pdf") || die "cannot create pdf: " . $Fop->errstr;
# create a PDF using an xsl-fo file
$Fop->fop(fo=>"foo.fo", outfile=>"temp2.pdf") || die "cannot create pdf: " . $Fop->errstr;
# create a PostScript file using an xsl-fo file
$Fop->fop(fo=>"foo.fo", outfile=>"temp3.ps", rendertype=>"ps") || die "cannot create ps file: " . $Fop->errstr;
# reset FOP's image cache (available starting with FOP version 0.20.5)
$Fop->reset_image_cache() || die "could not reset FOP's image cache: " . $Fop->errstr;
DESCRIPTION
XML::ApacheFOP allows you to create PDFs (or other output types, explained below) using Apache FOP.
Since FOP is written in Java, this module relies on Java.pm. You will need to have FOP and Java.pm installed before installing this module.
SETUP
The biggest hurdle in getting this module to work will be installing and setting up FOP and Java.pm. I recommend you thoroughly read the FOP and Java.pm documentation.
You will also need Java2 1.2.x or later installed. See the "SEE ALSO" section below for a download link.
Once you have them installed, you will need to make a change to the JavaServer startup so that FOP will be accessible. The -classpath will need to be tailored to suit your system. Hopefully the following example will help you get it right though. Here is the command I use:
/path/to/java -classpath \
/path/to/JavaServer.jar\
:/usr/local/xml-fop/build/fop.jar\
:/usr/local/xml-fop/lib/avalon-framework-cvs-20020806.jar\
:/usr/local/xml-fop/lib/batik.jar\
:/usr/local/xml-fop/lib/xalan-2.4.1.jar\
:/usr/local/xml-fop/lib/xercesImpl-2.2.1.jar \
com.zzo.javaserver.JavaServer
Once your JavaServer is running you'll be ready to start using this module.
The README file included with this distribution contains more help for getting this module setup.
METHODS
new
This will connect to the JavaServer and return a Fop object. It will die if it cannot connect to the JavaServer.
The new call accepts a hash with the following keys: (note that many of these options are the same as those in Java.pm)
host => hostname of remote machine to connect to
default is 'localhost'
port => port the JVM is listening on (JavaServer)
default is 2000
event_port => port that the remote JVM will send events to
default is -1 (off)
Since this module doesn't do any GUI work, leaving this
off is a good idea as the second event port will NOT
get used/opened saving some system resources.
authfile => The path to a file whose first line is used as a
shared 'secret' which will be passed to
JavaServer. To use this feature you must start
JavaServer with the '--authfile=<filename>'
command-line option.
If the secret words match access will be granted
to this client. By default there is no shared
secret. See the 'Authorization' section in Java.pm docs for more info.
debug => when set to true it will print various warn messages stating what
the module is doing. Default is false.
allowed_paths => this is an array ref containing the allowed paths for any filename
passed to this module (such as xml, xsl, fo, or pdf filenames).
For example, if set to ['/home/foo'], then only files within
/home/foo or its children directories will be allowed. If any files
outside of this path are passed, the fop call will fail.
Default is undef, meaning files from anywhere are allowed.
fop
This makes the actual call to FOP.
The fop call accepts a hash with the following keys:
fo => path to the xsl-fo file, must I<not> be used with xml and xsl
xml => path to the xml file, must be used together with xsl
xsl => path to xsl stylesheet, must be used together with xml
outfile => filename to save the generated file as
rendertype => the type of file that should be generated.
Default is pdf. Also supports the following formats:
mif - will be rendered as mif file
pcl - will be rendered as pcl file
ps - will be rendered as PostScript file
txt - will be rendered as text file
svg - will be rendered as a svg slides file
at - representation of area tree as XML
txt_encoding => if the 'txt' rendertype is used, this is the
output encoding used for the outfile.
The encoding must be a valid java encoding.
s => if the 'at' rendertype is used, setting this to true
will omit the tree below block areas.
c => the path to an xml configuration file of options
such as baseDir, fontBaseDir, and strokeSVGText.
See http://xmlgraphics.apache.org/fop/configuration.html
Will return 1 if the call is successfull.
Will return undef if there was a problem. In this case, $Fop->errstr will contain a string explaining what went wrong.
reset_image_cache
Instruct FOP to clear its image cache. This method is available starting with FOP version 0.20.5. For more information, see http://xmlgraphics.apache.org/fop/graphics.html#caching
Will return 1 on success. Will return undef on failure, in which case the error message will be accessible via $Fop->errstr.
errstr
Will return an error message if the previous $Fop method call failed.
AUTHOR
Ken Prows (perl@xev.net)
SEE ALSO
Please let me know if any of the below links are broken.
Java2: http://java.sun.com/j2se/
Java.pm: http://search.cpan.org/perldoc?Java
SourceForge page for Java.pm/JavaServer: http://sourceforge.net/projects/javaserver/
FOP: http://xmlgraphics.apache.org/fop/
Ken Neighbors has created Debian packages for Java.pm/JavaServer and XML::ApacheFOP. This greatly eases the installation for the Debian platform: http://www.nsds.com/software/
COPYRIGHT and LICENSE
Copyright (C) 2005 Online-Rewards. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.