tuto3.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. require('../fpdf.php');
  3. class PDF extends FPDF
  4. {
  5. function Header()
  6. {
  7. global $titre;
  8. //Arial gras 15
  9. $this->SetFont('Arial','B',15);
  10. //Calcul de la largeur du titre et positionnement
  11. $w=$this->GetStringWidth($titre)+6;
  12. $this->SetX((210-$w)/2);
  13. //Couleurs du cadre, du fond et du texte
  14. $this->SetDrawColor(0,80,180);
  15. $this->SetFillColor(230,230,0);
  16. $this->SetTextColor(220,50,50);
  17. //Epaisseur du cadre (1 mm)
  18. $this->SetLineWidth(1);
  19. //Titre centré
  20. $this->Cell($w,9,$titre,1,1,'C',true);
  21. //Saut de ligne
  22. $this->Ln(10);
  23. }
  24. function Footer()
  25. {
  26. //Positionnement à 1,5 cm du bas
  27. $this->SetY(-15);
  28. //Arial italique 8
  29. $this->SetFont('Arial','I',8);
  30. //Couleur du texte en gris
  31. $this->SetTextColor(128);
  32. //Numéro de page
  33. $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
  34. }
  35. function TitreChapitre($num,$lib)
  36. {
  37. //Arial 12
  38. $this->SetFont('Arial','',12);
  39. //Couleur de fond
  40. $this->SetFillColor(200,220,255);
  41. //Titre
  42. $this->Cell(0,6,"Chapitre $num : $lib",0,1,'L',true);
  43. //Saut de ligne
  44. $this->Ln(4);
  45. }
  46. function CorpsChapitre($fichier)
  47. {
  48. //Lecture du fichier texte
  49. $f=fopen($fichier,'r');
  50. $txt=fread($f,filesize($fichier));
  51. fclose($f);
  52. //Times 12
  53. $this->SetFont('Times','',12);
  54. //Sortie du texte justifié
  55. $this->MultiCell(0,5,$txt);
  56. //Saut de ligne
  57. $this->Ln();
  58. //Mention en italique
  59. $this->SetFont('','I');
  60. $this->Cell(0,5,'(fin de l\'extrait)');
  61. }
  62. function AjouterChapitre($num,$titre,$fichier)
  63. {
  64. $this->AddPage();
  65. $this->TitreChapitre($num,$titre);
  66. $this->CorpsChapitre($fichier);
  67. }
  68. }
  69. $pdf=new PDF();
  70. $titre='Vingt mille lieues sous les mers';
  71. $pdf->SetTitle($titre);
  72. $pdf->SetAuthor('Jules Verne');
  73. $pdf->AjouterChapitre(1,'UN ÉCUEIL FUYANT','20k_c1.txt');
  74. $pdf->AjouterChapitre(2,'LE POUR ET LE CONTRE','20k_c2.txt');
  75. $pdf->Output();
  76. ?>