]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/pdf.php
include [all] Include and file path should be devided with single space. File path...
[SourceForge/phpwiki.git] / lib / pdf.php
1 <?php // -*-php-*-
2
3 /*
4  * Copyright (C) 2003 Olivier PLATHEY
5  * Copyright (C) 200? Don SebĂ 
6  * Copyright (C) 2004,2006,2007 Reini Urban
7  *
8  * This file is part of PhpWiki.
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 //define("USE_EXTERNAL_HTML2PDF", "htmldoc --quiet --format pdf14 --jpeg --webpage --no-toc --no-title %s");
26 /**
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
31 */
32 function ConvertAndDisplayPdfPageList (&$request, $pagelist, $args = array()) {
33     global $WikiTheme;
34     if (empty($request->_is_buffering_output))
35         $request->buffer_output(false/*'nocompress'*/);
36     $pagename = $request->getArg('pagename');
37     $dest = $request->getArg('dest');
38     $request->setArg('dest',false);
39     $request->setArg('format',false);
40     include_once 'lib/display.php';
41     include_once 'lib/loadsave.php';
42
43     array_unshift($pagelist->_pages, $request->_dbi->getPage($pagename));
44     require_once 'lib/WikiPluginCached.php';
45     $cache = new WikiPluginCached;
46     $cache->newCache();
47     $tmpfile = $cache->tempnam();
48     $tmpdir = dirname($tmpfile);
49     unlink ($tmpfile);
50
51     $WikiTheme->DUMP_MODE = 'PDFHTML';
52     _DumpHtmlToDir($tmpdir,
53                new WikiDB_Array_generic_iter($pagelist->_pages),
54                $request->getArg('exclude'));
55     $WikiTheme->DUMP_MODE = false;
56     return;
57 }
58
59 /*
60  * Main action handler: action=pdf
61  * TODO: inline cached content: /getimg.php? => image.png
62  * Just use an external exe.
63  */
64 function ConvertAndDisplayPdf (&$request) {
65     global $WikiTheme;
66     if (empty($request->_is_buffering_output))
67         $request->buffer_output(false/*'nocompress'*/);
68     $pagename = $request->getArg('pagename');
69     $dest = $request->getArg('dest');
70     // Disable CACHE
71
72     $WikiTheme->DUMP_MODE = true;
73     include_once 'lib/display.php';
74     // TODO: urldecode pagename to get rid of %20 in filename.pdf
75     displayPage($request, new Template('htmldump', $request));
76     $html = ob_get_contents();
77     $WikiTheme->DUMP_MODE = false;
78
79     // check hook for external converters
80     if (defined('USE_EXTERNAL_HTML2PDF')
81         and USE_EXTERNAL_HTML2PDF)
82     {   // See http://phpwiki.sourceforge.net/phpwiki/PhpWikiToDocBookAndPDF
83         // htmldoc or ghostscript + html2ps or docbook (dbdoclet, xsltproc, fop)
84         Header('Content-Type: application/pdf');
85         $request->discardOutput();
86         $request->buffer_output(false/*'nocompress'*/);
87         require_once 'lib/WikiPluginCached.php';
88         $cache = new WikiPluginCached;
89         $cache->newCache();
90         $tmpfile = $cache->tempnam('pdf.html');
91         $fp = fopen($tmpfile, "wb");
92         fwrite($fp, $html);
93         fclose($fp);
94         passthru(sprintf(USE_EXTERNAL_HTML2PDF, $tmpfile));
95         unlink($tmpfile);
96     }
97     // clean the hints errors
98     global $ErrorManager;
99     $ErrorManager->destroyPostponedErrors();
100
101     if (!empty($errormsg)) {
102         $request->discardOutput();
103     }
104 }
105
106 // Local Variables:
107 // mode: php
108 // tab-width: 8
109 // c-basic-offset: 4
110 // c-hanging-comment-ender-p: nil
111 // indent-tabs-mode: nil
112 // End: