1 | <?php |
---|
2 | define('FPDF_FONTPATH','../font/'); |
---|
3 | require('../fpdf.php'); |
---|
4 | |
---|
5 | class PDF extends FPDF |
---|
6 | { |
---|
7 | //Current column |
---|
8 | var $col=0; |
---|
9 | //Ordinate of column start |
---|
10 | var $y0; |
---|
11 | |
---|
12 | function Header() |
---|
13 | { |
---|
14 | //Page header |
---|
15 | global $title; |
---|
16 | |
---|
17 | $this->SetFont('Arial','B',15); |
---|
18 | $w=$this->GetStringWidth($title)+6; |
---|
19 | $this->SetX((210-$w)/2); |
---|
20 | $this->SetDrawColor(0,80,180); |
---|
21 | $this->SetFillColor(230,230,0); |
---|
22 | $this->SetTextColor(220,50,50); |
---|
23 | $this->SetLineWidth(1); |
---|
24 | $this->Cell($w,9,$title,1,1,'C',1); |
---|
25 | $this->Ln(10); |
---|
26 | //Save ordinate |
---|
27 | $this->y0=$this->GetY(); |
---|
28 | } |
---|
29 | |
---|
30 | function Footer() |
---|
31 | { |
---|
32 | //Page footer |
---|
33 | $this->SetY(-15); |
---|
34 | $this->SetFont('Arial','I',8); |
---|
35 | $this->SetTextColor(128); |
---|
36 | $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C'); |
---|
37 | } |
---|
38 | |
---|
39 | function SetCol($col) |
---|
40 | { |
---|
41 | //Set position at a given column |
---|
42 | $this->col=$col; |
---|
43 | $x=10+$col*65; |
---|
44 | $this->SetLeftMargin($x); |
---|
45 | $this->SetX($x); |
---|
46 | } |
---|
47 | |
---|
48 | function AcceptPageBreak() |
---|
49 | { |
---|
50 | //Method accepting or not automatic page break |
---|
51 | if($this->col<2) |
---|
52 | { |
---|
53 | //Go to next column |
---|
54 | $this->SetCol($this->col+1); |
---|
55 | //Set ordinate to top |
---|
56 | $this->SetY($this->y0); |
---|
57 | //Keep on page |
---|
58 | return false; |
---|
59 | } |
---|
60 | else |
---|
61 | { |
---|
62 | //Go back to first column |
---|
63 | $this->SetCol(0); |
---|
64 | //Page break |
---|
65 | return true; |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | function ChapterTitle($num,$label) |
---|
70 | { |
---|
71 | //Title |
---|
72 | $this->SetFont('Arial','',12); |
---|
73 | $this->SetFillColor(200,220,255); |
---|
74 | $this->Cell(0,6,"Chapter $num : $label",0,1,'L',1); |
---|
75 | $this->Ln(4); |
---|
76 | //Save ordinate |
---|
77 | $this->y0=$this->GetY(); |
---|
78 | } |
---|
79 | |
---|
80 | function ChapterBody($fichier) |
---|
81 | { |
---|
82 | //Read text file |
---|
83 | $f=fopen($fichier,'r'); |
---|
84 | $txt=fread($f,filesize($fichier)); |
---|
85 | fclose($f); |
---|
86 | //Font |
---|
87 | $this->SetFont('Times','',12); |
---|
88 | //Output text in a 6 cm width column |
---|
89 | $this->MultiCell(60,5,$txt); |
---|
90 | $this->Ln(); |
---|
91 | //Mention |
---|
92 | $this->SetFont('','I'); |
---|
93 | $this->Cell(0,5,'(end of excerpt)'); |
---|
94 | //Go back to first column |
---|
95 | $this->SetCol(0); |
---|
96 | } |
---|
97 | |
---|
98 | function PrintChapter($num,$title,$file) |
---|
99 | { |
---|
100 | //Add chapter |
---|
101 | $this->AddPage(); |
---|
102 | $this->ChapterTitle($num,$title); |
---|
103 | $this->ChapterBody($file); |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | $pdf=new PDF(); |
---|
108 | $title='20000 Leagues Under the Seas'; |
---|
109 | $pdf->SetTitle($title); |
---|
110 | $pdf->SetAuthor('Jules Verne'); |
---|
111 | $pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt'); |
---|
112 | $pdf->PrintChapter(2,'THE PROS AND CONS','20k_c2.txt'); |
---|
113 | $pdf->Output(); |
---|
114 | ?> |
---|