tuto3.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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',1);
  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',1);
  43. //Line break
  44. $this->Ln(4);
  45. }
  46. function ChapterBody($file)
  47. {
  48. //Read text file
  49. $f=fopen($file,'r');
  50. $txt=fread($f,filesize($file));
  51. fclose($f);
  52. //Times 12
  53. $this->SetFont('Times','',12);
  54. //Output justified text
  55. $this->MultiCell(0,5,$txt);
  56. //Line break
  57. $this->Ln();
  58. //Mention in italics
  59. $this->SetFont('','I');
  60. $this->Cell(0,5,'(end of excerpt)');
  61. }
  62. function PrintChapter($num,$title,$file)
  63. {
  64. $this->AddPage();
  65. $this->ChapterTitle($num,$title);
  66. $this->ChapterBody($file);
  67. }
  68. }
  69. $pdf=new PDF();
  70. $title='20000 Leagues Under the Seas';
  71. $pdf->SetTitle($title);
  72. $pdf->SetAuthor('Jules Verne');
  73. $pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt');
  74. $pdf->PrintChapter(2,'THE PROS AND CONS','20k_c2.txt');
  75. $pdf->Output();
  76. ?>