home *** CD-ROM | disk | FTP | other *** search
- fo to pdf converter.
-
- with fo (formating objects) it's quite easy to convert xml-documents into
- pdf-docs (and not only pdf, but also ps, pcl, txt and more)
-
- An introduction into formating objects can be found at
- http://www.w3.org/TR/xsl/slice6.html#fo-section
- http://www.ibiblio.org/xml/books/bible/updates/15.html
- A tutorial is here:
- http://www.xml.com/pub/a/2001/01/17/xsl-fo/
- http://www.xml.com/pub/a/2001/01/24/xsl-fo/
- A html_to_fo.xsl can also be found there
- http://www.xml.com/2001/01/24/xsl-fo/fop_article.tgz
- but it didn't work for my simple xhtml files..
-
- The way to use this class is, produce a fo-file from a xml-file with a
- xsl-stylesheet, then feed this class with this fo-file and you get a pdf
- back (either directly to the browser for really dynamic-pdf production or
- as a file on your filesystem)
-
- It is recommended to use the Cache-Classes from PEAR, if you want dynamic
- pdf production, since the process of making the pdfs takes some time. For
- an example of how to use Cache and fo2pdf see below.
-
- Requirements:
-
- - You need Fop (version 0.20.1 was used for testing) from the xml-apache
- project (http://xml.apache.org/fop) and Java (1.1.x or later, i tested
- it with 1.2.2 from sun on linux, see the Fop-Docs for details).
-
- - Furthermore you have to compile your php with --with-java and to adjust
- your php.ini file. It can be a rather painful task to get java and php
- to work together. (i also tested this only with jdk 1.2.2, got 1.3.1 to work
- but not together with sablotron....)
- See http://www.phpbuilder.com/columns/marknold20001221.php3 or
- http://www.linuxwebdevnews.com/articles/php-java-xslt.php?pid=347 or
- http://www.onlamp.com/pub/a/php/2001/06/14/php_jav.html or
- http://php.chregu.tv/java-debian.html (some config tips)
- for more details about java and php.
- For your reference, my relevant parts in php.ini looks like this:
- ***
- extension=libphp_java.so
- extension.dir=/usr/local/lib/php/20010901/
- [java]
- java.class.path=/usr/local/lib/php/php_java.jar:/usr/local/share/java/fop.jar:/usr/local/share/java/batik.jar:/usr/share/java/xalan-2.0.1.jar:/usr/share/java/xerces.jar:/usr/local/share/java/jimi-1.0.jar
- java.library=/usr/lib/java/jre/lib/i386/libjava.so
- ***
-
-
- - If you want to include images or svg-files, then FOP needs an XServer (this is a
- limitation of the graphics-support in java. See
- http://www.geocities.com/marcoschmidt.geo/java-image-coding.html
- for details). Normally webservers don't have Xservers installed, but I made
- some good experiences with Xfvb.
-
- Usage:
- require_once("XML/fo2pdf.php");
- //make a pdf from simple.fo and save the pdf in a tmp-folder
- $fop = new xml_fo2pdf();
- // the following 2 lines are the default settins, so not
- // necessary here, but you can set it to other values
- $fop->setRenderer("pdf");
- $fop->setContentType("application/pdf");
- //If you want other fonts in your PDF, you need to declare them in a
- // config file. Declare here the path to this file [optional].
- // More information about fonts and fop on the apache-fop webpage.
- $fop->setConfigFile("userconfig.xml");
- if (PEAR::isError($error = $fop->run("simple.fo")))
- {
- die("FOP ERROR: ". $error->getMessage());
- }
- //print pdf to the outputbuffer,
- // including correct Header ("Content-type: application/pdf")
- $fop->printPDF();
- //delete the temporary pdf file
- $fop->deletePDF();
-
- With Cache:
- require_once("XML/fo2pdf.php");
- require_once("Cache/Output.php");
- $container = "file";
- $options = array("cache_dir"=>"/tmp/");
- $cache = new Cache_Output("$container",$options);
- $cache_handle = $cache->generateID($REQUEST_URI);
- if ($content = $cache->start($cache_handle)) {
- Header("Content-type: application/pdf");
- print $content;
- die();
- }
- $fop = new xml_fo2pdf();
- $fop->run("simple.fo");
- $fop->printPDF();
- $fop->deletePDF();
- print $cache->end("+30");
-
-