Created
April 19, 2025 04:12
-
-
Save estefanionsantos/0b5ac7d3c31c68c6e2c5ea5b3e5950d5 to your computer and use it in GitHub Desktop.
fpdf-tuto3-1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Rubricate\Fpdf\FileFpdf; | |
class PDF extends FileFpdf | |
{ | |
public function Header() | |
{ | |
global $title; | |
$w = $this->getStringWidth($title) + 6; | |
$this->setFont('Arial','B',15); | |
$this->setX((210 - $w)/2); | |
$this->setDrawColor(0, 80, 180); | |
$this->setFillColor(230, 230, 0); | |
$this->setTextColor(220, 50, 50); | |
$this->setLineWidth(1); | |
$this->cell($w, 9, $title, 1, 1, 'C', true); | |
$this->ln(10); | |
} | |
public function Footer() | |
{ | |
$this->setY(-15); | |
$this->setFont('Arial','I',8); | |
$this->setTextColor(128); | |
$this->cell(0, 10, 'Page '. $this->PageNo(), 0, 0, 'C'); | |
} | |
public function ChapterTitle($num, $label) | |
{ | |
$this->setFont('Arial','',12); | |
$this->setFillColor(200,220,255); | |
$this->cell(0,6, "Chapter $num : $label", 0, 1, 'L', true); | |
$this->ln(4); | |
} | |
public function ChapterBody($file) | |
{ | |
$txt = file_get_contents($file); | |
$this->setFont('Times','', 12); | |
$this->multiCell(0, 5, $txt); | |
$this->ln(); | |
$this->setFont('', 'I'); | |
$this->cell(0, 5, '(end of excerpt)'); | |
} | |
public function PrintChapter($num, $title, $file) | |
{ | |
$this->addPage(); | |
$this->chapterTitle($num, $title); | |
$this->chapterBody($file); | |
} | |
} | |
$title = '20000 Leagues Under the Seas'; | |
$pdf = new PDF(); | |
$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(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment