]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/pdf.php
renamed global $Theme to $WikiTheme (gforge nameclash)
[SourceForge/phpwiki.git] / lib / pdf.php
1 <?php // -*-php-*-
2 rcs_id('$Id: pdf.php,v 1.4 2004-06-14 11:31:37 rurban Exp $');
3
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
9
10 require_once('lib/fpdf.php');
11
12 class PDF extends FPDF {
13     var $B = 0;
14     var $I = 0;
15     var $U = 0;
16     var $HREF = '';
17
18     function PDF ($orientation='P', $unit='mm', $format='A4') {
19         $this->FPDF($orientation,$unit,$format);
20         //$this->SetCompression(false);
21     }
22
23     // Simple HTML to PDF converter
24     function ConvertFromHTML($html) {
25         $html = str_replace("\n",' ',$html);
26         $a = preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
27         foreach($a as $i=>$e) {
28             if ($i % 2 == 0) {
29                 //Text
30                 if($this->HREF)
31                     $this->PutLink($this->HREF,$e);
32                 else
33                     $this->Write(5,$e);
34             } else {
35                 //Tag
36                 if ($e{0} == '/')
37                     $this->CloseTag(strtoupper(substr($e,1)));
38                 else {
39                     //Attributes
40                     $a2 = explode(' ',$e);
41                     $tag = strtoupper(array_shift($a2));
42                     $attr = array();
43                     foreach ($a2 as $v)
44                         if (ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3))
45                             $attr[strtoupper($a3[1])]=$a3[2];
46                     $this->OpenTag($tag,$attr);
47                 }
48             }
49         }
50     }
51
52     function Header() {
53         $this->SetY(-15);
54         $this->SetFont('Arial','',9);
55         //URL - space from side - space from top - width
56         if (!DEBUG) {
57           $imgurl = $GLOBALS['WikiTheme']->_findFile("images/logo.png"); // header and wikilogo
58           if ($imgurl)
59             $this->Image($imgurl,3,3);
60         }
61         //Line break
62         //$this->Ln(30);
63     }
64
65     function Footer() {
66         //global $cfg, $config, $lang;
67         //1.5cm below top
68         $this->SetY(-15);
69         //Arial italic 8
70         $this->SetFont('arial','I',8);
71     }
72
73     function OpenTag($tag,$attr) {
74         if($tag=='B' or $tag=='I' or $tag=='U')
75             $this->SetStyle($tag,true);
76         if($tag=='A')
77             $this->HREF=$attr['HREF'];
78         if($tag=='BR')
79             $this->Ln(5);
80     }
81
82     function CloseTag($tag) {
83         if($tag=='B' or $tag=='I' or $tag=='U')
84             $this->SetStyle($tag,false);
85         if($tag=='A')
86             $this->HREF='';
87     }
88     
89     //Wijzig stijl en selecteer lettertype
90     function SetStyle($tag,$enable) {
91         $this->$tag+=($enable ? 1 : -1);
92         $style='';
93         foreach(array('B','I','U') as $s)
94             if($this->$s > 0)
95                 $style .= $s;
96         $this->SetFont('',$style);
97     }
98
99     function PutLink($URL,$txt) {
100         // hyperlink as simple underlined text
101         $this->SetTextColor(0,0,255);
102         $this->SetStyle('U',true);
103         $this->Write(5,$txt,$URL);
104         $this->SetStyle('U',false);
105         $this->SetTextColor(0);
106     }
107 }
108
109 function ConvertAndDisplayPdf (&$request) {
110     if (empty($request->_is_buffering_output))
111         $request->buffer_output(false/*'nocompress'*/);
112     if ($GLOBALS['LANG'] == 'ja') {
113         include_once("lib/fpdf/japanese.php");
114         $pdf = new PDF_Japanese;
115     } elseif ($GLOBALS['LANG'] == 'zh') {
116         include_once("lib/fpdf/chinese.php");
117         $pdf = new PDF_Chinese;
118     } else {
119         $pdf = new PDF;
120     }
121     include_once("lib/display.php");
122     displayPage($request);
123     $html = ob_get_contents();
124     $pdf->Open();
125     $pdf->AddPage();
126     $pdf->ConvertFromHTML($html);
127     $request->discardOutput();
128         
129     $request->buffer_output(false/*'nocompress'*/);
130     $pagename = $request->getArg('pagename');
131     $dest = $request->getArg('dest');
132     $pdf->Output($pagename.".pdf", $dest ? $dest : 'F');
133     if (!empty($errormsg)) {
134         $request->discardOutput();
135     }
136 }
137
138 // $Log: not supported by cvs2svn $
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 ?>