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