Statistics
| Branch: | Revision:

root / evote / costastest / fpdf / tutorial / tuto3.php @ f52a1778

History | View | Annotate | Download (1.6 kB)

1
<?php
2
require('../fpdf.php');
3

    
4
class PDF extends FPDF
5
{
6
function Header()
7
{
8
        global $title;
9

    
10
        // Arial bold 15
11
        $this->SetFont('Arial','B',15);
12
        // Calculate width of title and position
13
        $w = $this->GetStringWidth($title)+6;
14
        $this->SetX((210-$w)/2);
15
        // Colors of frame, background and text
16
        $this->SetDrawColor(0,80,180);
17
        $this->SetFillColor(230,230,0);
18
        $this->SetTextColor(220,50,50);
19
        // Thickness of frame (1 mm)
20
        $this->SetLineWidth(1);
21
        // Title
22
        $this->Cell($w,9,$title,1,1,'C',true);
23
        // Line break
24
        $this->Ln(10);
25
}
26

    
27
function Footer()
28
{
29
        // Position at 1.5 cm from bottom
30
        $this->SetY(-15);
31
        // Arial italic 8
32
        $this->SetFont('Arial','I',8);
33
        // Text color in gray
34
        $this->SetTextColor(128);
35
        // Page number
36
        $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
37
}
38

    
39
function ChapterTitle($num, $label)
40
{
41
        // Arial 12
42
        $this->SetFont('Arial','',12);
43
        // Background color
44
        $this->SetFillColor(200,220,255);
45
        // Title
46
        $this->Cell(0,6,"Chapter $num : $label",0,1,'L',true);
47
        // Line break
48
        $this->Ln(4);
49
}
50

    
51
function ChapterBody($file)
52
{
53
        // Read text file
54
        $txt = file_get_contents($file);
55
        // Times 12
56
        $this->SetFont('Times','',12);
57
        // Output justified text
58
        $this->MultiCell(0,5,$txt);
59
        // Line break
60
        $this->Ln();
61
        // Mention in italics
62
        $this->SetFont('','I');
63
        $this->Cell(0,5,'(end of excerpt)');
64
}
65

    
66
function PrintChapter($num, $title, $file)
67
{
68
        $this->AddPage();
69
        $this->ChapterTitle($num,$title);
70
        $this->ChapterBody($file);
71
}
72
}
73

    
74
$pdf = new PDF();
75
$title = '20000 Leagues Under the Seas';
76
$pdf->SetTitle($title);
77
$pdf->SetAuthor('Jules Verne');
78
$pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt');
79
$pdf->PrintChapter(2,'THE PROS AND CONS','20k_c2.txt');
80
$pdf->Output();
81
?>