]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/pdf.php
Use UTF-8 so that display is correct on sf.net
[SourceForge/phpwiki.git] / lib / pdf.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
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
21  along with PhpWiki; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 // $Log: not supported by cvs2svn $
107 // Revision 1.13  2007/09/15 12:28:46  rurban
108 // Improve multi-page format handling: abstract _DumpHtmlToDir. get rid of non-external pdf, non-global VALID_LINKS
109 //
110 // Revision 1.12  2007/09/12 19:41:38  rurban
111 // Enable format=pdf for pagelists (not yet finished)
112 //
113 // Revision 1.11  2007/02/17 14:14:55  rurban
114 // fix pagename for lists
115 //
116 // Revision 1.10  2007/01/07 18:44:39  rurban
117 // Add ConvertAndDisplayPdfPageList
118 //
119 // Revision 1.9  2006/09/06 06:02:05  rurban
120 // omit actionbar from pdf
121 //
122 // Revision 1.8  2006/08/25 22:09:00  rurban
123 // print pdf header earlier
124 //
125 // Revision 1.7  2004/09/22 13:46:26  rurban
126 // centralize upload paths.
127 // major WikiPluginCached feature enhancement:
128 //   support _STATIC pages in uploads/ instead of dynamic getimg.php? subrequests.
129 //   mainly for debugging, cache problems and action=pdf
130 //
131 // Revision 1.6  2004/09/20 13:40:19  rurban
132 // define all config.ini settings, only the supported will be taken from -default.
133 // support USE_EXTERNAL_HTML2PDF renderer (htmldoc tested)
134 //
135 // Revision 1.5  2004/09/17 14:19:02  rurban
136 // default pdf dest: browser
137 //
138 // Revision 1.4  2004/06/14 11:31:37  rurban
139 // renamed global $Theme to $WikiTheme (gforge nameclash)
140 // inherit PageList default options from PageList
141 //   default sortby=pagename
142 // use options in PageList_Selectable (limit, sortby, ...)
143 // added action revert, with button at action=diff
144 // added option regex to WikiAdminSearchReplace
145 //
146 // Revision 1.3  2004/05/15 19:49:09  rurban
147 // moved action_pdf to lib/pdf.php
148 //
149
150 // Local Variables:
151 // mode: php
152 // tab-width: 8
153 // c-basic-offset: 4
154 // c-hanging-comment-ender-p: nil
155 // indent-tabs-mode: nil
156 // End:
157 ?>