]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/pdf.php
Allow bold, italics or underlined for numbers
[SourceForge/phpwiki.git] / lib / pdf.php
1 <?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 {
34     global $WikiTheme;
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';
43
44     array_unshift($pagelist->_pages, $request->_dbi->getPage($pagename));
45     require_once 'lib/WikiPluginCached.php';
46     $cache = new WikiPluginCached;
47     $cache->newCache();
48     $tmpfile = $cache->tempnam();
49     $tmpdir = dirname($tmpfile);
50     unlink($tmpfile);
51
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;
57     return;
58 }
59
60 /*
61  * Main action handler: action=pdf
62  * TODO: inline cached content: /getimg.php? => image.png
63  * Just use an external exe.
64  */
65 function ConvertAndDisplayPdf(&$request)
66 {
67     global $WikiTheme;
68     if (empty($request->_is_buffering_output))
69         $request->buffer_output(false /*'nocompress'*/);
70     $pagename = $request->getArg('pagename');
71     $dest = $request->getArg('dest');
72     // Disable CACHE
73
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;
80
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;
91         $cache->newCache();
92         $tmpfile = $cache->tempnam('pdf.html');
93         $fp = fopen($tmpfile, "wb");
94         fwrite($fp, $html);
95         fclose($fp);
96         passthru(sprintf(USE_EXTERNAL_HTML2PDF, $tmpfile));
97         unlink($tmpfile);
98     }
99     // clean the hints errors
100     global $ErrorManager;
101     $ErrorManager->destroyPostponedErrors();
102
103     if (!empty($errormsg)) {
104         $request->discardOutput();
105     }
106 }
107
108 // Local Variables:
109 // mode: php
110 // tab-width: 8
111 // c-basic-offset: 4
112 // c-hanging-comment-ender-p: nil
113 // indent-tabs-mode: nil
114 // End: