Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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
	$txt = file_get_contents($file);
83
	// Font
84
	$this->SetFont('Times','',12);
85
	// Output text in a 6 cm width column
86
	$this->MultiCell(60,5,$txt);
87
	$this->Ln();
88
	// Mention
89
	$this->SetFont('','I');
90
	$this->Cell(0,5,'(end of excerpt)');
91
	// Go back to first column
92
	$this->SetCol(0);
93
}
94
 
95
function PrintChapter($num, $title, $file)
96
{
97
	// Add chapter
98
	$this->AddPage();
99
	$this->ChapterTitle($num,$title);
100
	$this->ChapterBody($file);
101
}
102
}
103
 
104
$pdf = new PDF();
105
$title = '20000 Leagues Under the Seas';
106
$pdf->SetTitle($title);
107
$pdf->SetAuthor('Jules Verne');
108
$pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt');
109
$pdf->PrintChapter(2,'THE PROS AND CONS','20k_c2.txt');
110
$pdf->Output();
111
?>