/** * This is the final Step in this 3 steps process: * <ol> * <li>Step 1 consists in generating the XML bsaed raw data for the report. </li> * <li>Step 2 consists in merging this raw data with a XSL-FO template to give it * the presentation information. XSL-FO acts as an intermediate language used * to render the final repor in any format with a last transformation. </li> * <li>Step 3 consists on rendering the XSL-FO representtion (the intermediate * language) of the report to the PDF output fromat.</li> * <ol> * * @param DOMDocument $xslFo The XSL-FO representation of the processed * report, as we get it just after step 2 in this 3 steps process. * @param sfWebResponse $response The Response Object, should be passed all * the way down from the action. So we can change some headers', ContentType * to 'application/pdf'. * * @see %sf_plugins_dir%/NeatReports/config/sfExportGlobals.yml * @return String With the rendered report content. PDF Binary stream returned * by ApacheFop. */ public function renderReport(DOMDocument $xslFo, sfWebResponse $response = null) { $response->setContentType('application/pdf'); $response->setHttpHeader('Content-Disposition', "attachment; filename=report.pdf"); $tStamp = microtime(true); $executable = stristr(PHP_OS, "WIN") ? 'fop.cmd' : 'fop'; $output = array(); $returnVar = 0; $foPath = __DIR__ . '/RenderPDF/tmp/report.fo.' . $tStamp; $pdfPath = __DIR__ . '/RenderPDF/tmp/report.pdf.' . $tStamp; try { file_put_contents($foPath, $xslFo->saveXML()); $command = $this->_fopPath . $executable . ' -fo ' . $foPath . ' -pdf ' . $pdfPath; exec($command, $output, $returnVar); if ((bool) $returnVar) { throw new Exception(implode(PHP_EOL, $output), $returnVar); } } catch (Exception $e) { $ex = new Exception('Error executing Apache FOP, return value is pased to Exception Code.' . ' Command execution output follows:' . PHP_EOL . implode(PHP_EOL, $output), $returnVar, $e); throw $ex; } $out = file_get_contents($pdfPath); unlink($foPath); unlink($pdfPath); return $out; }
/** * This is the final Step in this 3 steps process: * <ol> * <li>Step 1 consists in generating the XML bsaed raw data for the report. </li> * <li>Step 2 consists in merging this raw data with a XSL-FO template to give it * the presentation information. XSL-FO acts as an intermediate language used * to render the final repor in any format with a last transformation. </li> * <li>Step 3 consists on rendering the XSL-FO representtion (the intermediate * language) of the report to the PDF output fromat.</li> * <ol> * Note that the PDF, will force download. You can override this. * * @param DOMDocument $xslFo The XSL-FO representation of the processed * report, as we get it just after step 2 in this 3 steps process. * @param sfWebResponse $response The Response Object, should be passed all * the way down from the action. So we can change some headers', ContentType * to 'application/pdf'. * * @see %sf_plugins_dir%/NeatReports/config/sfExportGlobals.yml * @return String With the rendered report content. PDF Binary stream returned * by ApacheFop. */ public function renderReport(DOMDocument $xslFo, sfWebResponse $response = null) { $response->setContentType('application/pdf'); $response->setHttpHeader('Content-Disposition', "attachment; filename=report.pdf"); $this->_pdfRenderer = new RenderPDFConsummer($xslFo->saveXML()); return $this->_pdfRenderer->getPdfStream(); }