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