tuto4.php

Go to the documentation of this file.
00001 <?php
00002 require('../fpdf.php');
00003 
00004 class PDF extends FPDF
00005 {
00006 //Current column
00007 var $col=0;
00008 //Ordinate of column start
00009 var $y0;
00010 
00011 function Header()
00012 {
00013     //Page header
00014     global $title;
00015 
00016     $this->SetFont('Arial','B',15);
00017     $w=$this->GetStringWidth($title)+6;
00018     $this->SetX((210-$w)/2);
00019     $this->SetDrawColor(0,80,180);
00020     $this->SetFillColor(230,230,0);
00021     $this->SetTextColor(220,50,50);
00022     $this->SetLineWidth(1);
00023     $this->Cell($w,9,$title,1,1,'C',true);
00024     $this->Ln(10);
00025     //Save ordinate
00026     $this->y0=$this->GetY();
00027 }
00028 
00029 function Footer()
00030 {
00031     //Page footer
00032     $this->SetY(-15);
00033     $this->SetFont('Arial','I',8);
00034     $this->SetTextColor(128);
00035     $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
00036 }
00037 
00038 function SetCol($col)
00039 {
00040     //Set position at a given column
00041     $this->col=$col;
00042     $x=10+$col*65;
00043     $this->SetLeftMargin($x);
00044     $this->SetX($x);
00045 }
00046 
00047 function AcceptPageBreak()
00048 {
00049     //Method accepting or not automatic page break
00050     if($this->col<2)
00051     {
00052         //Go to next column
00053         $this->SetCol($this->col+1);
00054         //Set ordinate to top
00055         $this->SetY($this->y0);
00056         //Keep on page
00057         return false;
00058     }
00059     else
00060     {
00061         //Go back to first column
00062         $this->SetCol(0);
00063         //Page break
00064         return true;
00065     }
00066 }
00067 
00068 function ChapterTitle($num,$label)
00069 {
00070     //Title
00071     $this->SetFont('Arial','',12);
00072     $this->SetFillColor(200,220,255);
00073     $this->Cell(0,6,"Chapter $num : $label",0,1,'L',true);
00074     $this->Ln(4);
00075     //Save ordinate
00076     $this->y0=$this->GetY();
00077 }
00078 
00079 function ChapterBody($file)
00080 {
00081     //Read text file
00082     $f=fopen($file,'r');
00083     $txt=fread($f,filesize($file));
00084     fclose($f);
00085     //Font
00086     $this->SetFont('Times','',12);
00087     //Output text in a 6 cm width column
00088     $this->MultiCell(60,5,$txt);
00089     $this->Ln();
00090     //Mention
00091     $this->SetFont('','I');
00092     $this->Cell(0,5,'(end of excerpt)');
00093     //Go back to first column
00094     $this->SetCol(0);
00095 }
00096 
00097 function PrintChapter($num,$title,$file)
00098 {
00099     //Add chapter
00100     $this->AddPage();
00101     $this->ChapterTitle($num,$title);
00102     $this->ChapterBody($file);
00103 }
00104 }
00105 
00106 $pdf=new PDF();
00107 $title='20000 Leagues Under the Seas';
00108 $pdf->SetTitle($title);
00109 $pdf->SetAuthor('Jules Verne');
00110 $pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt');
00111 $pdf->PrintChapter(2,'THE PROS AND CONS','20k_c2.txt');
00112 $pdf->Output();
00113 ?>
 All Data Structures Files Functions Variables Enumerations