2 rcs_id('$Id: pdf.php,v 1.6 2004-09-20 13:40:19 rurban Exp $');
4 // PDF functions taken from FPDF http://www.fpdf.org
5 // Edited for PHPWebthings by Don SebĂ
6 // Feel free to edit , enhance the module, and please share it at http://www.phpdbform.com
7 // Keep PHPWT COOL submit your modules/themes/mods, it will help to improve ! :)
8 // Changes for PhpWiki by Reini Urban
10 require_once('lib/fpdf.php');
12 // http://phpwiki.sourceforge.net/phpwiki/PhpWikiToDocBookAndPDF
13 // htmldoc or ghostscript + html2ps or docbook (dbdoclet, xsltproc, fop)
14 // http://www.easysw.com/htmldoc
15 //define("USE_EXTERNAL_HTML2PDF", "htmldoc --quiet --format pdf14 --no-toc --no-title %s");
17 class PDF extends FPDF {
23 function PDF ($orientation='P', $unit='mm', $format='A4') {
24 $this->FPDF($orientation,$unit,$format);
25 //$this->SetCompression(false);
28 // Simple HTML to PDF converter
29 function ConvertFromHTML($html) {
30 $html = str_replace("\n",' ',$html);
31 $a = preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
32 foreach($a as $i=>$e) {
36 $this->PutLink($this->HREF,$e);
42 $this->CloseTag(strtoupper(substr($e,1)));
45 $a2 = explode(' ',$e);
46 $tag = strtoupper(array_shift($a2));
49 if (ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3))
50 $attr[strtoupper($a3[1])]=$a3[2];
51 $this->OpenTag($tag,$attr);
59 $this->SetFont('Arial','',9);
60 //URL - space from side - space from top - width
62 $imgurl = $GLOBALS['WikiTheme']->_findFile("images/logo.png"); // header and wikilogo
64 $this->Image($imgurl,3,3);
71 //global $cfg, $config, $lang;
75 $this->SetFont('arial','I',8);
78 function OpenTag($tag,$attr) {
79 if($tag=='B' or $tag=='I' or $tag=='U')
80 $this->SetStyle($tag,true);
82 $this->HREF=$attr['HREF'];
87 function CloseTag($tag) {
88 if($tag=='B' or $tag=='I' or $tag=='U')
89 $this->SetStyle($tag,false);
94 //Wijzig stijl en selecteer lettertype
95 function SetStyle($tag,$enable) {
96 $this->$tag+=($enable ? 1 : -1);
98 foreach(array('B','I','U') as $s)
101 $this->SetFont('',$style);
104 function PutLink($URL,$txt) {
105 // hyperlink as simple underlined text
106 $this->SetTextColor(0,0,255);
107 $this->SetStyle('U',true);
108 $this->Write(5,$txt,$URL);
109 $this->SetStyle('U',false);
110 $this->SetTextColor(0);
114 function ConvertAndDisplayPdf (&$request) {
115 if (empty($request->_is_buffering_output))
116 $request->buffer_output(false/*'nocompress'*/);
117 $pagename = $request->getArg('pagename');
118 $dest = $request->getArg('dest');
120 include_once("lib/display.php");
121 displayPage($request);
122 $html = ob_get_contents();
124 // check hook for external converters
125 if (defined('USE_EXTERNAL_HTML2PDF')
126 and USE_EXTERNAL_HTML2PDF)
127 { // See http://phpwiki.sourceforge.net/phpwiki/PhpWikiToDocBookAndPDF
128 // htmldoc or ghostscript + html2ps or docbook (dbdoclet, xsltproc, fop)
129 $request->discardOutput();
130 $request->buffer_output(false/*'nocompress'*/);
131 require_once("lib/WikiPluginCached.php");
132 $cache = new WikiPluginCached;
134 $tmpfile = $cache->tempnam();
135 $fp = fopen($tmpfile, "wb");
138 Header('Content-Type: application/pdf');
139 passthru(sprintf(USE_EXTERNAL_HTML2PDF, $tmpfile));
143 if ($GLOBALS['LANG'] == 'ja') {
144 include_once("lib/fpdf/japanese.php");
145 $pdf = new PDF_Japanese;
146 } elseif ($GLOBALS['LANG'] == 'zh') {
147 include_once("lib/fpdf/chinese.php");
148 $pdf = new PDF_Chinese;
154 $pdf->ConvertFromHTML($html);
155 $request->discardOutput();
156 $request->buffer_output(false/*'nocompress'*/);
157 $pdf->Output($pagename.".pdf", $dest ? $dest : 'I');
159 if (!empty($errormsg)) {
160 $request->discardOutput();
164 // $Log: not supported by cvs2svn $
165 // Revision 1.5 2004/09/17 14:19:02 rurban
166 // default pdf dest: browser
168 // Revision 1.4 2004/06/14 11:31:37 rurban
169 // renamed global $Theme to $WikiTheme (gforge nameclash)
170 // inherit PageList default options from PageList
171 // default sortby=pagename
172 // use options in PageList_Selectable (limit, sortby, ...)
173 // added action revert, with button at action=diff
174 // added option regex to WikiAdminSearchReplace
176 // Revision 1.3 2004/05/15 19:49:09 rurban
177 // moved action_pdf to lib/pdf.php
184 // c-hanging-comment-ender-p: nil
185 // indent-tabs-mode: nil