]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/pdf.php
better experimental PDF support
[SourceForge/phpwiki.git] / lib / pdf.php
1 <?php // -*-php-*-
2 rcs_id('$Id: pdf.php,v 1.1 2004-03-26 00:22: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
9 require_once('lib/fpdf.php');
10
11 class PDF extends FPDF {
12     var $B = 0;
13     var $I = 0;
14     var $U = 0;
15     var $HREF = '';
16
17     function PDF ($orientation='P', $unit='mm', $format='A4') {
18         $this->FPDF($orientation,$unit,$format);
19     }
20
21     // Simple HTML to PDF converter
22     function ConvertFromHTML($html) {
23         $html = str_replace("\n",' ',$html);
24         $a = preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
25         foreach($a as $i=>$e) {
26             if ($i % 2 == 0) {
27                 //Tekst
28                 if($this->HREF)
29                     $this->PutLink($this->HREF,$e);
30                 else
31                     $this->Write(5,$e);
32             } else {
33                 //Tag
34                 if ($e{0} == '/')
35                     $this->CloseTag(strtoupper(substr($e,1)));
36                 else {
37                     //Filter de attributen
38                     $a2 = explode(' ',$e);
39                     $tag = strtoupper(array_shift($a2));
40                     $attr = array();
41                     foreach ($a2 as $v)
42                         if (ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3))
43                             $attr[strtoupper($a3[1])]=$a3[2];
44                     $this->OpenTag($tag,$attr);
45                 }
46             }
47         }
48     }
49
50     /* not yet used */
51     function Header() {
52         //URL - space from side - space from top - width
53         $imgurl = "..."; // header and wikilogo
54         $this->Image($imgurl,3,3,$imgwidth);
55         //Line break
56         $this->Ln(30);
57     }
58
59     /* not yet used */
60     function Footer() {
61         //global $cfg, $config, $lang;
62         //Positie 1.5 cm van de onderkant
63         $this->SetY(-15);
64         //Arial cursief 8
65         $this->SetFont('Arial','I',8);
66         //Page number
67         //$this->Cell(0,10,$cfg["core"]["url"],0,0,'C');
68         //$this->Cell(0,10,' Page '.$this->PageNo().'/{nb}',0,0,'C');
69     }
70
71     function OpenTag($tag,$attr) {
72         if($tag=='B' or $tag=='I' or $tag=='U')
73             $this->SetStyle($tag,true);
74         if($tag=='A')
75             $this->HREF=$attr['HREF'];
76         if($tag=='BR')
77             $this->Ln(5);
78     }
79
80     function CloseTag($tag) {
81         if($tag=='B' or $tag=='I' or $tag=='U')
82             $this->SetStyle($tag,false);
83         if($tag=='A')
84             $this->HREF='';
85     }
86     
87     //Wijzig stijl en selecteer lettertype
88     function SetStyle($tag,$enable) {
89         $this->$tag+=($enable ? 1 : -1);
90         $style='';
91         foreach(array('B','I','U') as $s)
92             if($this->$s>0)
93                 $style.=$s;
94         $this->SetFont('',$style);
95     }
96
97     function PutLink($URL,$txt) {
98         // hyperlink as simple underlined text
99         $this->SetTextColor(0,0,255);
100         $this->SetStyle('U',true);
101         $this->Write(5,$txt,$URL);
102         $this->SetStyle('U',false);
103         $this->SetTextColor(0);
104     }
105 }
106
107 // Local Variables:
108 // mode: php
109 // tab-width: 8
110 // c-basic-offset: 4
111 // c-hanging-comment-ender-p: nil
112 // indent-tabs-mode: nil
113 // End:
114 ?>