westdc-zf1/include/fpdf/tutorial/tuto3.php

82 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2009-03-06 03:20:46 +00:00
<?php
require('../fpdf.php');
class PDF extends FPDF
{
function Header()
{
global $title;
2011-11-03 02:25:38 +00:00
// Arial bold 15
2009-03-06 03:20:46 +00:00
$this->SetFont('Arial','B',15);
2011-11-03 02:25:38 +00:00
// Calculate width of title and position
$w = $this->GetStringWidth($title)+6;
2009-03-06 03:20:46 +00:00
$this->SetX((210-$w)/2);
2011-11-03 02:25:38 +00:00
// Colors of frame, background and text
2009-03-06 03:20:46 +00:00
$this->SetDrawColor(0,80,180);
$this->SetFillColor(230,230,0);
$this->SetTextColor(220,50,50);
2011-11-03 02:25:38 +00:00
// Thickness of frame (1 mm)
2009-03-06 03:20:46 +00:00
$this->SetLineWidth(1);
2011-11-03 02:25:38 +00:00
// Title
2009-03-06 03:20:46 +00:00
$this->Cell($w,9,$title,1,1,'C',true);
2011-11-03 02:25:38 +00:00
// Line break
2009-03-06 03:20:46 +00:00
$this->Ln(10);
}
function Footer()
{
2011-11-03 02:25:38 +00:00
// Position at 1.5 cm from bottom
2009-03-06 03:20:46 +00:00
$this->SetY(-15);
2011-11-03 02:25:38 +00:00
// Arial italic 8
2009-03-06 03:20:46 +00:00
$this->SetFont('Arial','I',8);
2011-11-03 02:25:38 +00:00
// Text color in gray
2009-03-06 03:20:46 +00:00
$this->SetTextColor(128);
2011-11-03 02:25:38 +00:00
// Page number
2009-03-06 03:20:46 +00:00
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}
2011-11-03 02:25:38 +00:00
function ChapterTitle($num, $label)
2009-03-06 03:20:46 +00:00
{
2011-11-03 02:25:38 +00:00
// Arial 12
2009-03-06 03:20:46 +00:00
$this->SetFont('Arial','',12);
2011-11-03 02:25:38 +00:00
// Background color
2009-03-06 03:20:46 +00:00
$this->SetFillColor(200,220,255);
2011-11-03 02:25:38 +00:00
// Title
2009-03-06 03:20:46 +00:00
$this->Cell(0,6,"Chapter $num : $label",0,1,'L',true);
2011-11-03 02:25:38 +00:00
// Line break
2009-03-06 03:20:46 +00:00
$this->Ln(4);
}
function ChapterBody($file)
{
2011-11-03 02:25:38 +00:00
// Read text file
$txt = file_get_contents($file);
// Times 12
2009-03-06 03:20:46 +00:00
$this->SetFont('Times','',12);
2011-11-03 02:25:38 +00:00
// Output justified text
2009-03-06 03:20:46 +00:00
$this->MultiCell(0,5,$txt);
2011-11-03 02:25:38 +00:00
// Line break
2009-03-06 03:20:46 +00:00
$this->Ln();
2011-11-03 02:25:38 +00:00
// Mention in italics
2009-03-06 03:20:46 +00:00
$this->SetFont('','I');
$this->Cell(0,5,'(end of excerpt)');
}
2011-11-03 02:25:38 +00:00
function PrintChapter($num, $title, $file)
2009-03-06 03:20:46 +00:00
{
$this->AddPage();
$this->ChapterTitle($num,$title);
$this->ChapterBody($file);
}
}
2011-11-03 02:25:38 +00:00
$pdf = new PDF();
$title = '20000 Leagues Under the Seas';
2009-03-06 03:20:46 +00:00
$pdf->SetTitle($title);
$pdf->SetAuthor('Jules Verne');
$pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt');
$pdf->PrintChapter(2,'THE PROS AND CONS','20k_c2.txt');
$pdf->Output();
?>