source: trunk/client/inc/hpdf/_fpdf/tutorial/tuto3.php@ 194

Last change on this file since 194 was 2, checked in by root, 15 years ago

importo il progetto

File size: 1.7 KB
Line 
1<?php
2require('../fpdf.php');
3
4class PDF extends FPDF
5{
6function 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
27function 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
39function 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
51function ChapterBody($file)
52{
53 //Read text file
54 $f=fopen($file,'r');
55 $txt=fread($f,filesize($file));
56 fclose($f);
57 //Times 12
58 $this->SetFont('Times','',12);
59 //Output justified text
60 $this->MultiCell(0,5,$txt);
61 //Line break
62 $this->Ln();
63 //Mention in italics
64 $this->SetFont('','I');
65 $this->Cell(0,5,'(end of excerpt)');
66}
67
68function PrintChapter($num,$title,$file)
69{
70 $this->AddPage();
71 $this->ChapterTitle($num,$title);
72 $this->ChapterBody($file);
73}
74}
75
76$pdf=new PDF();
77$title='20000 Leagues Under the Seas';
78$pdf->SetTitle($title);
79$pdf->SetAuthor('Jules Verne');
80$pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt');
81$pdf->PrintChapter(2,'THE PROS AND CONS','20k_c2.txt');
82$pdf->Output();
83?>
Note: See TracBrowser for help on using the repository browser.