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”/>

restart
/etc/init.d/tomcat5.5 restart
open browser (no trailing forward slash at the end)
https://ubuntu.local:8180
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)

PART 2
setting up cocoon download cocoon from http://cocoon.apache.org/mirror.cgi
<code>
wget http://east.unified.net/apache/cocoon/cocoon-2.1.11-src.tar.gz
tar -xvf cocoon-2.1.11-src.tar.gz
cd cocoon-2.1.11
./build.sh war
</code>
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.
https://ubuntu.local:8180
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 java.io.FilePermission “/var/lib/tomcat5.5/webapps/cocoon/WEB-INF/classes/logging.properties”, “read”;
permission java.io.FilePermission “/usr/share/tomcat5.5-webapps/jsp-examples/WEB-INF/classes/logging.properties”, “read”;
permission java.io.FilePermission “/usr/share/tomcat5.5-webapps/servlets-examples/WEB-INF/classes/logging.properties”, “read”;
};</pre>
security errors were also encountered on page load of: http://192.168.0.1:8180/cocoon/ easiest fix was to turn off security checks.
enable this option:
vim /etc/default/tomcat5.5
add this:
TOMCAT5_SECURITY=no
restart tomcat:
/etc/init.d/tomcat5.5 restart
view the sample pdf as included by cocoon:
http://192.168.0.1:8180/cocoon/samples/blocks/itext/hello.pdf
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.
context://samples/hello-world/content/hello.xml
defines the data location

context://samples/hello-world/style/xsl/page2itext.xsl

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 asp.net websites!

Be the first to comment

Leave a Reply

Your email address will not be published.


*