4 * Copyright (C) 2003 Olivier PLATHEY
5 * Copyright (C) 200? Don SebĂ
6 * Copyright (C) 2004,2006,2007 Reini Urban
8 * This file is part of PhpWiki.
10 * PhpWiki is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * PhpWiki is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 //define("USE_EXTERNAL_HTML2PDF", "htmldoc --quiet --format pdf14 --jpeg --webpage --no-toc --no-title %s");
27 * handler for format=pdf
28 * http://phpwiki.sourceforge.net/phpwiki/PhpWikiToDocBookAndPDF
29 * htmldoc or ghostscript + html2ps or docbook (dbdoclet, xsltproc, fop)
30 * http://www.easysw.com/htmldoc
32 function ConvertAndDisplayPdfPageList(&$request, $pagelist, $args = array())
35 if (empty($request->_is_buffering_output))
36 $request->buffer_output(false /*'nocompress'*/);
37 $pagename = $request->getArg('pagename');
38 $dest = $request->getArg('dest');
39 $request->setArg('dest', false);
40 $request->setArg('format', false);
41 include_once 'lib/display.php';
42 include_once 'lib/loadsave.php';
44 array_unshift($pagelist->_pages, $request->_dbi->getPage($pagename));
45 require_once 'lib/WikiPluginCached.php';
46 $cache = new WikiPluginCached;
48 $tmpfile = $cache->tempnam();
49 $tmpdir = dirname($tmpfile);
52 $WikiTheme->DUMP_MODE = 'PDFHTML';
53 _DumpHtmlToDir($tmpdir,
54 new WikiDB_Array_generic_iter($pagelist->_pages),
55 $request->getArg('exclude'));
56 $WikiTheme->DUMP_MODE = false;
61 * Main action handler: action=pdf
62 * TODO: inline cached content: /getimg.php? => image.png
63 * Just use an external exe.
65 function ConvertAndDisplayPdf(&$request)
68 if (empty($request->_is_buffering_output))
69 $request->buffer_output(false /*'nocompress'*/);
70 $pagename = $request->getArg('pagename');
71 $dest = $request->getArg('dest');
74 $WikiTheme->DUMP_MODE = true;
75 include_once 'lib/display.php';
76 // TODO: urldecode pagename to get rid of %20 in filename.pdf
77 displayPage($request, new Template('htmldump', $request));
78 $html = ob_get_contents();
79 $WikiTheme->DUMP_MODE = false;
81 // check hook for external converters
82 if (defined('USE_EXTERNAL_HTML2PDF')
83 and USE_EXTERNAL_HTML2PDF
84 ) { // See http://phpwiki.sourceforge.net/phpwiki/PhpWikiToDocBookAndPDF
85 // htmldoc or ghostscript + html2ps or docbook (dbdoclet, xsltproc, fop)
86 Header('Content-Type: application/pdf');
87 $request->discardOutput();
88 $request->buffer_output(false /*'nocompress'*/);
89 require_once 'lib/WikiPluginCached.php';
90 $cache = new WikiPluginCached;
92 $tmpfile = $cache->tempnam('pdf.html');
93 $fp = fopen($tmpfile, "wb");
96 passthru(sprintf(USE_EXTERNAL_HTML2PDF, $tmpfile));
99 // clean the hints errors
100 global $ErrorManager;
101 $ErrorManager->destroyPostponedErrors();
103 if (!empty($errormsg)) {
104 $request->discardOutput();
112 // c-hanging-comment-ender-p: nil
113 // indent-tabs-mode: nil