tuto3.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. require('../fpdf.php');
  3. class PDF extends FPDF
  4. {
  5. function Header()
  6. {
  7. global $title;
  8. // Arial bold 15
  9. $this->SetFont('Arial','B',15);
  10. // Calculate width of title and position
  11. $w = $this->GetStringWidth($title)+6;
  12. $this->SetX((210-$w)/2);
  13. // Colors of frame, background and text
  14. $this->SetDrawColor(0,80,180);
  15. $this->SetFillColor(230,230,0);
  16. $this->SetTextColor(220,50,50);
  17. // Thickness of frame (1 mm)
  18. $this->SetLineWidth(1);
  19. // Title
  20. $this->Cell($w,9,$title,1,1,'C',true);
  21. // Line break
  22. $this->Ln(10);
  23. }
  24. function Footer()
  25. {
  26. // Position at 1.5 cm from bottom
  27. $this->SetY(-15);
  28. // Arial italic 8
  29. $this->SetFont('Arial','I',8);
  30. // Text color in gray
  31. $this->SetTextColor(128);
  32. // Page number
  33. $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
  34. }
  35. function ChapterTitle($num, $label)
  36. {
  37. // Arial 12
  38. $this->SetFont('Arial','',12);
  39. // Background color
  40. $this->SetFillColor(200,220,255);
  41. // Title
  42. $this->Cell(0,6,"Chapter $num : $label",0,1,'L',true);
  43. // Line break
  44. $this->Ln(4);
  45. }
  46. function ChapterBody($file)
  47. {
  48. // Read text file
  49. $txt = file_get_contents($file);
  50. // Times 12
  51. $this->SetFont('Times','',12);
  52. // Output justified text
  53. $this->MultiCell(0,5,$txt);
  54. // Line break
  55. $this->Ln();
  56. // Mention in italics
  57. $this->SetFont('','I');
  58. $this->Cell(0,5,'(end of excerpt)');
  59. }
  60. function PrintChapter($num, $title, $file)
  61. {
  62. $this->AddPage();
  63. $this->ChapterTitle($num,$title);
  64. $this->ChapterBody($file);
  65. }
  66. }
  67. $pdf = new PDF();
  68. $title = '20000 Leagues Under the Seas';
  69. $pdf->SetTitle($title);
  70. $pdf->SetAuthor('Jules Verne');
  71. $pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt');
  72. $pdf->PrintChapter(2,'THE PROS AND CONS','20k_c2.txt');
  73. $pdf->Output();
  74. ?>