tuto3.php

Go to the documentation of this file.
00001 <?php
00002 require('../fpdf.php');
00003 
00004 class PDF extends FPDF
00005 {
00006 function Header()
00007 {
00008     global $title;
00009 
00010     //Arial bold 15
00011     $this->SetFont('Arial','B',15);
00012     //Calculate width of title and position
00013     $w=$this->GetStringWidth($title)+6;
00014     $this->SetX((210-$w)/2);
00015     //Colors of frame, background and text
00016     $this->SetDrawColor(0,80,180);
00017     $this->SetFillColor(230,230,0);
00018     $this->SetTextColor(220,50,50);
00019     //Thickness of frame (1 mm)
00020     $this->SetLineWidth(1);
00021     //Title
00022     $this->Cell($w,9,$title,1,1,'C',true);
00023     //Line break
00024     $this->Ln(10);
00025 }
00026 
00027 function Footer()
00028 {
00029     //Position at 1.5 cm from bottom
00030     $this->SetY(-15);
00031     //Arial italic 8
00032     $this->SetFont('Arial','I',8);
00033     //Text color in gray
00034     $this->SetTextColor(128);
00035     //Page number
00036     $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
00037 }
00038 
00039 function ChapterTitle($num,$label)
00040 {
00041     //Arial 12
00042     $this->SetFont('Arial','',12);
00043     //Background color
00044     $this->SetFillColor(200,220,255);
00045     //Title
00046     $this->Cell(0,6,"Chapter $num : $label",0,1,'L',true);
00047     //Line break
00048     $this->Ln(4);
00049 }
00050 
00051 function ChapterBody($file)
00052 {
00053     //Read text file
00054     $f=fopen($file,'r');
00055     $txt=fread($f,filesize($file));
00056     fclose($f);
00057     //Times 12
00058     $this->SetFont('Times','',12);
00059     //Output justified text
00060     $this->MultiCell(0,5,$txt);
00061     //Line break
00062     $this->Ln();
00063     //Mention in italics
00064     $this->SetFont('','I');
00065     $this->Cell(0,5,'(end of excerpt)');
00066 }
00067 
00068 function PrintChapter($num,$title,$file)
00069 {
00070     $this->AddPage();
00071     $this->ChapterTitle($num,$title);
00072     $this->ChapterBody($file);
00073 }
00074 }
00075 
00076 $pdf=new PDF();
00077 $title='20000 Leagues Under the Seas';
00078 $pdf->SetTitle($title);
00079 $pdf->SetAuthor('Jules Verne');
00080 $pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt');
00081 $pdf->PrintChapter(2,'THE PROS AND CONS','20k_c2.txt');
00082 $pdf->Output();
00083 ?>
 All Data Structures Files Functions Variables Enumerations