function ConvertAndDisplayPdf(&$request) { global $WikiTheme; if (empty($request->_is_buffering_output)) { $request->buffer_output(false); } $pagename = $request->getArg('pagename'); $dest = $request->getArg('dest'); // Disable CACHE $WikiTheme->DUMP_MODE = true; include_once "lib/display.php"; // TODO: urldecode pagename to get rid of %20 in filename.pdf displayPage($request, new Template('htmldump', $request)); $html = ob_get_contents(); $WikiTheme->DUMP_MODE = false; // check hook for external converters if (defined('USE_EXTERNAL_HTML2PDF') and USE_EXTERNAL_HTML2PDF) { // See http://phpwiki.sourceforge.net/phpwiki/PhpWikiToDocBookAndPDF // htmldoc or ghostscript + html2ps or docbook (dbdoclet, xsltproc, fop) Header('Content-Type: application/pdf'); $request->discardOutput(); $request->buffer_output(false); require_once "lib/WikiPluginCached.php"; $cache = new WikiPluginCached(); $cache->newCache(); $tmpfile = $cache->tempnam('pdf.html'); $fp = fopen($tmpfile, "wb"); fwrite($fp, $html); fclose($fp); passthru(sprintf(USE_EXTERNAL_HTML2PDF, $tmpfile)); unlink($tmpfile); } // clean the hints errors global $ErrorManager; $ErrorManager->destroyPostponedErrors(); if (!empty($errormsg)) { $request->discardOutput(); } }
function ConvertAndDisplayPdf(&$request) { if (empty($request->_is_buffering_output)) { $request->buffer_output(false); } $pagename = $request->getArg('pagename'); $dest = $request->getArg('dest'); //TODO: inline cached content: /getimg.php? => image.png // Disable CACHE include_once "lib/display.php"; displayPage($request); $html = ob_get_contents(); // check hook for external converters if (defined('USE_EXTERNAL_HTML2PDF') and USE_EXTERNAL_HTML2PDF) { // See http://phpwiki.sourceforge.net/phpwiki/PhpWikiToDocBookAndPDF // htmldoc or ghostscript + html2ps or docbook (dbdoclet, xsltproc, fop) $request->discardOutput(); $request->buffer_output(false); require_once "lib/WikiPluginCached.php"; $cache = new WikiPluginCached(); $cache->newCache(); $tmpfile = $cache->tempnam(); $fp = fopen($tmpfile, "wb"); fwrite($fp, $html); fclose($fp); Header('Content-Type: application/pdf'); passthru(sprintf(USE_EXTERNAL_HTML2PDF, $tmpfile)); unlink($tmpfile); } else { // use fpdf: if ($GLOBALS['LANG'] == 'ja') { include_once "lib/fpdf/japanese.php"; $pdf = new PDF_Japanese(); } elseif ($GLOBALS['LANG'] == 'zh') { include_once "lib/fpdf/chinese.php"; $pdf = new PDF_Chinese(); } else { $pdf = new PDF(); } $pdf->Open(); $pdf->AddPage(); $pdf->ConvertFromHTML($html); $request->discardOutput(); $request->buffer_output(false); $pdf->Output($pagename . ".pdf", $dest ? $dest : 'I'); } if (!empty($errormsg)) { $request->discardOutput(); } }