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. // Calculamos ancho y posición del título.
  11. $w = $this->GetStringWidth($title)+6;
  12. $this->SetX((210-$w)/2);
  13. // Colores de los bordes, fondo y texto
  14. $this->SetDrawColor(0,80,180);
  15. $this->SetFillColor(230,230,0);
  16. $this->SetTextColor(220,50,50);
  17. // Ancho del borde (1 mm)
  18. $this->SetLineWidth(1);
  19. // Título
  20. $this->Cell($w,9,$title,1,1,'C',true);
  21. // Salto de línea
  22. $this->Ln(10);
  23. }
  24. function Footer()
  25. {
  26. // Posición a 1,5 cm del final
  27. $this->SetY(-15);
  28. // Arial itálica 8
  29. $this->SetFont('Arial','I',8);
  30. // Color del texto en gris
  31. $this->SetTextColor(128);
  32. // Número de página
  33. $this->Cell(0,10,'Página '.$this->PageNo(),0,0,'C');
  34. }
  35. function ChapterTitle($num, $label)
  36. {
  37. // Arial 12
  38. $this->SetFont('Arial','',12);
  39. // Color de fondo
  40. $this->SetFillColor(200,220,255);
  41. // Título
  42. $this->Cell(0,6,"Capítulo $num : $label",0,1,'L',true);
  43. // Salto de línea
  44. $this->Ln(4);
  45. }
  46. function ChapterBody($file)
  47. {
  48. // Leemos el fichero
  49. $txt = file_get_contents($file);
  50. // Times 12
  51. $this->SetFont('Times','',12);
  52. // Imprimimos el texto justificado
  53. $this->MultiCell(0,5,$txt);
  54. // Salto de línea
  55. $this->Ln();
  56. // Cita en itálica
  57. $this->SetFont('','I');
  58. $this->Cell(0,5,'(fin del extracto)');
  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 Leguas de Viaje Submarino';
  69. $pdf->SetTitle($title);
  70. $pdf->SetAuthor('Julio Verne');
  71. $pdf->PrintChapter(1,'UN RIZO DE HUIDA','20k_c1.txt');
  72. $pdf->PrintChapter(2,'LOS PROS Y LOS CONTRAS','20k_c2.txt');
  73. $pdf->Output();
  74. ?>