True Dynamic PDF Generation

I did this about 2 years ago. Not much has changed but there has been more steps involved due to security issues and bug fixes. Here’s the current instructions as they currently work today.

apt-get install sun-java6-jdk
apt-get install tomcat5.5
apt-get install tomcat5.5-admin
apt-get install tomcat5.5-webapps
vim /etc/tomcat5.5/tomcat-users.xml

add the following (not sure why admin and manager isn’t defined)

<role rolename=”manager”/>
<role rolename=”admin”/>
<user username=”####” password=”####” roles=”tomcat,role1,manager,admin”/>

/etc/init.d/tomcat5.5 restart
open browser (no trailing forward slash at the end)
should anything during the installation process go wrong, you can repeat the installation by purging the old files through apt-get –purge autoremove tomcat5.5, correct the mistake/problem, and retry the installation. for me, I had multiple java instances problems and having defined JAVA_HOME when it isn’t needed (in this setup scenario it is automatically found)

setting up cocoon download cocoon from
tar -xvf cocoon-2.1.11-src.tar.gz
cd cocoon-2.1.11
./ war
i got warnings of jpegencoder funnctions. i don’t need them.
cd build/cocoon
your cocoon.war file is here. use the manager interface to upload the cocoon file.
I have encountered a permission issue while browsing the catalina log file. to resolve this I had to add the following
vim /etc/tomcat5.5/policy.d/04webapps.policy
<pre>grant codeBase “file:${catalina.home}/bin/tomcat-juli.jar” {
permission “/var/lib/tomcat5.5/webapps/cocoon/WEB-INF/classes/”, “read”;
permission “/usr/share/tomcat5.5-webapps/jsp-examples/WEB-INF/classes/”, “read”;
permission “/usr/share/tomcat5.5-webapps/servlets-examples/WEB-INF/classes/”, “read”;
security errors were also encountered on page load of: easiest fix was to turn off security checks.
enable this option:
vim /etc/default/tomcat5.5
add this:
restart tomcat:
/etc/init.d/tomcat5.5 restart
view the sample pdf as included by cocoon:
if you browse to the directory you’ll notice that hello.pdf does not exist. Instead a sitemap.xmap helps define what hello.pdf should be generated from.
defines the data location


defines how the xml should be represented

&lt;<map:serialize type=”itext2pdf”/&gt;
defines the transformation mode

For our purposes we will be using XSL-FO so the transformer is:
&lt;map:serialize type=”fo2pdf”/&gt;

That’s it! you’ve got dynamic pdf generator. now you just have to learn the XSL-FO tags to create your pdf! A possible followup to this write up will cover query string and retriving source files remotely in a dynamic fashion. By doing so, you will then have the ability to create free dynamic PDF from any platform like websites!

Be the first to comment

Leave a Reply

Your email address will not be published.