00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 error_reporting(E_ALL);
00019 set_time_limit(1800);
00020
00021 include 'class.ezpdf.php';
00022
00023
00024 class Creport extends Cezpdf {
00025
00026 var $reportContents = array();
00027
00028 function Creport($p,$o){
00029 $this->Cezpdf($p,$o);
00030 }
00031
00032 function rf($info){
00033
00034
00035 $tmp = $info['p'];
00036 $lvl = $tmp[0];
00037 $lbl = rawurldecode(substr($tmp,1));
00038 $num=$this->ezWhatPageNumber($this->ezGetCurrentPageNumber());
00039 $this->reportContents[] = array($lbl,$num,$lvl );
00040 $this->addDestination('toc'.(count($this->reportContents)-1),'FitH',$info['y']+$info['height']);
00041 }
00042
00043 function dots($info){
00044
00045 $tmp = $info['p'];
00046 $lvl = $tmp[0];
00047 $lbl = substr($tmp,1);
00048 $xpos = 520;
00049
00050 switch($lvl){
00051 case '1':
00052 $size=16;
00053 $thick=1;
00054 break;
00055 case '2':
00056 $size=12;
00057 $thick=0.5;
00058 break;
00059 }
00060
00061 $this->saveState();
00062 $this->setLineStyle($thick,'round','',array(0,10));
00063 $this->line($xpos,$info['y'],$info['x']+5,$info['y']);
00064 $this->restoreState();
00065 $this->addText($xpos+5,$info['y'],$size,$lbl);
00066
00067
00068 }
00069
00070
00071 }
00072
00073
00074
00075
00076
00077 $pdf = new Creport('a4','portrait');
00078
00079 $pdf -> ezSetMargins(50,70,50,50);
00080
00081
00082 $all = $pdf->openObject();
00083 $pdf->saveState();
00084 $pdf->setStrokeColor(0,0,0,1);
00085 $pdf->line(20,40,578,40);
00086 $pdf->line(20,822,578,822);
00087 $pdf->addText(50,34,6,'http:
00088 $pdf->restoreState();
00089 $pdf->closeObject();
00090
00091
00092 $pdf->addObject($all,'all');
00093
00094 $pdf->ezSetDy(-100);
00095
00096
00097 $mainFont = './fonts/Times-Roman.afm';
00098 $codeFont = './fonts/Courier.afm';
00099
00100 $pdf->selectFont($mainFont);
00101
00102 $pdf->ezText("PHP Pdf Creation\n",30,array('justification'=>'centre'));
00103 $pdf->ezText("Module-free creation of Pdf documents\nfrom within PHP\n",20,array('justification'=>'centre'));
00104 $pdf->ezText("developed by R&OS Ltd\n<c:alink:http://www.ros.co.nz/pdf/>http://www.ros.co.nz/pdf</c:alink>",18,array('justification'=>'centre'));
00105 $pdf->ezText("\n<c:alink:http://sourceforge.net/projects/pdf-php>http://sourceforge.net/projects/pdf-php</c:alink>\n\nversion 0.09",18,array('justification'=>'centre'));
00106
00107 $pdf->ezSetDy(-100);
00108
00109
00110 $pdf->openHere('Fit');
00111
00112 function ros_logo(&$pdf,$x,$y,$height,$wl=0,$wr=0){
00113 $pdf->saveState();
00114 $h=100;
00115 $factor = $height/$h;
00116 $pdf->selectFont('./fonts/Helvetica-Bold.afm');
00117 $text = 'R&OS';
00118 $ts=100*$factor;
00119 $th = $pdf->getFontHeight($ts);
00120 $td = $pdf->getFontDecender($ts);
00121 $tw = $pdf->getTextWidth($ts,$text);
00122 $pdf->setColor(0.6,0,0);
00123 $z = 0.86;
00124 $pdf->filledRectangle($x-$wl,$y-$z*$h*$factor,$tw*1.2+$wr+$wl,$h*$factor*$z);
00125 $pdf->setColor(1,1,1);
00126 $pdf->addText($x,$y-$th-$td,$ts,$text);
00127 $pdf->setColor(0.6,0,0);
00128 $pdf->addText($x,$y-$th-$td,$ts*0.1,'http:
00129 $pdf->restoreState();
00130 return $height;
00131 }
00132
00133 ros_logo($pdf,150,$pdf->y-100,80,150,200);
00134 $pdf->selectFont($mainFont);
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 $data=file('./data.txt');
00151
00152
00153
00154 $faqFile = '../ros/pdf/faqs.inc';
00155 if (file_exists($faqFile)){
00156
00157 $data[] = "#NP\n";
00158 $data[] = "1<FAQs>\n";
00159 include($faqFile);
00160 foreach($faqs as $v){
00161 $data[] = "2<".$v['t'].">\n";
00162
00163 $s = array('<br>','<p>','<pre>','</pre>','<ul>','</ul>','<li>');
00164 $r = array("\n","\n\n","\n#C","\n#c","",""," - ");
00165 if (is_array($v['d'])){
00166 $tmp='';
00167 foreach($v['d'] as $section){
00168 $tmp.=$section."\n\n";
00169 }
00170 } else {
00171 $tmp = $v['d'];
00172 }
00173 $tmp = str_replace($s,$r,$tmp);
00174 $bits = explode("\n",$tmp);
00175 foreach($bits as $bit){
00176 $data[] = $bit."\n";
00177 }
00178 }
00179 }
00180
00181 $pdf->ezNewPage();
00182
00183 $pdf->ezStartPageNumbers(500,28,10,'','',1);
00184
00185 $size=12;
00186 $height = $pdf->getFontHeight($size);
00187 $textOptions = array('justification'=>'full');
00188 $collecting=0;
00189 $code='';
00190
00191 foreach ($data as $line){
00192
00193
00194 $line=chop($line);
00195 if (strlen($line) && $line[0]=='#'){
00196
00197 switch($line){
00198 case '#NP':
00199 $pdf->ezNewPage();
00200 break;
00201 case '#C':
00202 $pdf->selectFont($codeFont);
00203 $textOptions = array('justification'=>'left','left'=>20,'right'=>20);
00204 $size=10;
00205 break;
00206 case '#c':
00207 $pdf->selectFont($mainFont);
00208 $textOptions = array('justification'=>'full');
00209 $size=12;
00210 break;
00211 case '#X':
00212 $collecting=1;
00213 break;
00214 case '#x':
00215 $pdf->saveState();
00216 eval($code);
00217 $pdf->restoreState();
00218 $pdf->selectFont($mainFont);
00219 $code='';
00220 $collecting=0;
00221 break;
00222 }
00223 } else if ($collecting){
00224 $code.=$line;
00225
00226 } else if (((strlen($line)>1 && $line[1]=='<') ) && $line[strlen($line)-1]=='>') {
00227
00228 switch($line[0]){
00229 case '1':
00230 $tmp = substr($line,2,strlen($line)-3);
00231 $tmp2 = $tmp.'<C:rf:1'.rawurlencode($tmp).'>';
00232 $pdf->ezText($tmp2,26,array('justification'=>'centre'));
00233 break;
00234 default:
00235 $tmp = substr($line,2,strlen($line)-3);
00236
00237 $tmp2 = $tmp.'<C:rf:2'.rawurlencode($tmp).'>';
00238 $pdf->transaction('start');
00239 $ok=0;
00240 while (!$ok){
00241 $thisPageNum = $pdf->ezPageCount;
00242 $pdf->saveState();
00243 $pdf->setColor(0.9,0.9,0.9);
00244 $pdf->filledRectangle($pdf->ez['leftMargin'],$pdf->y-$pdf->getFontHeight(18)+$pdf->getFontDecender(18),$pdf->ez['pageWidth']-$pdf->ez['leftMargin']-$pdf->ez['rightMargin'],$pdf->getFontHeight(18));
00245 $pdf->restoreState();
00246 $pdf->ezText($tmp2,18,array('justification'=>'left'));
00247 if ($pdf->ezPageCount==$thisPageNum){
00248 $pdf->transaction('commit');
00249 $ok=1;
00250 } else {
00251
00252 $pdf->transaction('rewind');
00253 $pdf->ezNewPage();
00254 }
00255 }
00256 break;
00257 }
00258 } else {
00259
00260
00261 $pdf->ezText($line,$size,$textOptions);
00262 }
00263
00264 }
00265
00266 $pdf->ezStopPageNumbers(1,1);
00267
00268
00269 $pdf->ezInsertMode(1,1,'after');
00270 $pdf->ezNewPage();
00271 $pdf->ezText("Contents\n",26,array('justification'=>'centre'));
00272 $xpos = 520;
00273 $contents = $pdf->reportContents;
00274 foreach($contents as $k=>$v){
00275 switch ($v[2]){
00276 case '1':
00277 $y=$pdf->ezText('<c:ilink:toc'.$k.'>'.$v[0].'</c:ilink><C:dots:1'.$v[1].'>',16,array('aright'=>$xpos));
00278
00279 break;
00280 case '2':
00281 $pdf->ezText('<c:ilink:toc'.$k.'>'.$v[0].'</c:ilink><C:dots:2'.$v[1].'>',12,array('left'=>50,'aright'=>$xpos));
00282 break;
00283 }
00284 }
00285
00286
00287 if (isset($d) && $d){
00288 $pdfcode = $pdf->ezOutput(1);
00289 $pdfcode = str_replace("\n","\n<br>",htmlspecialchars($pdfcode));
00290 echo '<html><body>';
00291 echo trim($pdfcode);
00292 echo '</body></html>';
00293 } else {
00294 $pdf->ezStream();
00295 }
00296 ?>