Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


 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
 A tutorial is here:
 A html_to_fo.xsl can also be found there
  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.


- You need Fop (version 0.20.1 was used for testing) from the xml-apache 
   project ( 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 or or or (some config tips)
   for more details about java and php.
   For your reference, my relevant parts in php.ini looks like this:

- 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
    for details). Normally webservers don't have Xservers installed, but I made 
    some good experiences with Xfvb.

    //make a pdf from 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        
    //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.
     if (PEAR::isError($error = $fop->run("")))
      die("FOP ERROR: ". $error->getMessage());
    //print pdf to the outputbuffer,
    // including correct Header ("Content-type: application/pdf")
    //delete the temporary pdf file

   With Cache:
    $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;
    $fop = new xml_fo2pdf();
    print $cache->end("+30");