Advertisement
cuatl

Reemplazar variables definidas para FPDF.

Sep 15th, 2013
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. <?php
  2. /*
  3. * Jorge Martínez Mauricio <gz@tar.mx> http://tar.mx
  4. * reemplaza variables definidas en la generación de PDF con FPDF http://www.fpdf.org/
  5. */
  6. require_once("fpdf17/fpdf.php"); //requiere la biblioteca FPDF.
  7. class PDF extends FPDF {
  8.    /* parseVar(key string, value string)*/
  9.    function parseVar($key='',$value='') {
  10.       if(empty($key) or empty($value)) return;
  11.       $nb = $this->page;
  12.       for($n=1;$n<=$nb;$n++) {
  13.          $this->pages[$n] = str_replace($key,$value,$this->pages[$n]);
  14.       }
  15.    }
  16. }
  17. /*
  18. * Ejemplo, generamos documento tamaño carta,
  19. */
  20. $pdf = new PDF('P','mm','Letter');
  21. $pdf->AddPage();
  22. $pdf->SetFont('arial','B',36); //fuente
  23. $pdf->SetFillColor(169,214,194); //fondo
  24. $pdf->MultiCell(0,20,"Hola mundo, cruel y perverso\n\n{fechaHora}",0,1,'C',1); //texto + variable
  25. $pdf->parseVar('{fechaHora}',strftime("%c")); // convertimos la variable.
  26. $pdf->SetFont('arial','',12); //fuente
  27. $pdf->ln(5);
  28. $pdf->Cell(0,5,"#oribeliever",0,1);
  29. $pdf->Image("http://tar.mx/log/hermosoPeralta.jpg"); //imagen
  30. $pdf->Output("ejemploVariablesPDF.pdf",'D');
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement