source: branches/version-2_11-dev/data/module/fpdf/tutorial/tuto4.php @ 20993

Revision 20993, 2.2 KB checked in by Seasoft, 15 years ago (diff)

#1374 (依存ライブラリのアップデート)

  • FPDF 1.6 -> 1.7
  • FPDI 1.4 -> 1.4.1 (配置パスをFPDFから分離)
Line 
1<?php
2require('../fpdf.php');
3
4class PDF extends FPDF
5{
6// Current column
7var $col = 0;
8// Ordinate of column start
9var $y0;
10
11function 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
29function 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
38function 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
47function 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
68function 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
79function 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
95function 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?>
Note: See TracBrowser for help on using the repository browser.