, * Andreas Oesterreicher and * Rudolf Hangl . */ /** * Erstellt ein PDF mithilfe Apache FOP * * $xml = file_get_contents('/path/to/your/xmlfile.xml'); * $xsl = file_get_contenst('/path/to/your/xslfile.xsl'); * $fop = new fop(); * $pdf_filename = $fop->create_pdf($xml, $xsl); */ class fop { var $xml; var $xsl; /** * Konstruktor */ public function __construct() { //Apache FOP } public function generatePdf($xml, $xsl, $filename, $destination) { $tmppdf = tempnam('/tmp', 'FAS_FOP'); $tmpxml = tempnam('/tmp', 'FAS_FOP'); $tmpxsl = tempnam('/tmp', 'FAS_FOP'); $bytes1 = file_put_contents($tmpxml, $xml); $bytes2 = file_put_contents($tmpxsl, $xsl); exec("fop -xml {$tmpxml} -xsl {$tmpxsl} -pdf {$tmppdf} 2>&1", $output); //error_log("FOP Execute: fop -xml {$tmpxml} -xsl {$tmpxsl} -pdf {$tmppdf} 2>&1 b1:$bytes1 b2: $bytes2 Output: ".print_r($output, true)); @unlink($tmpxml); @unlink($tmpxsl); /*if(count($output)>0) exit(print_r($output, true));*/ switch($destination) { case "D": // Download $buffer = file_get_contents($tmppdf); if(headers_sent()) { echo 'Some data has already been output to browser, can\'t send PDF file'; break; } if(isset($_SERVER['HTTP_USER_AGENT']) && mb_strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) header('Content-Type: application/force-download'); else header('Content-Type: application/octet-stream'); header('Content-Length: '.mb_strlen($buffer)); header('Content-disposition: attachment; filename="'.$filename.'.pdf"'); echo $buffer; unlink($tmppdf); break; case "F": // im Filesystem speichern break; case "I": //auf Stdout ausgeben echo file_get_contents($tmppdf); break; } return($tmppdf); } } ?>