problem with the accents in fpdf

1

I have this code and when I save the pdf I get some strange letters. someone who can help me with this.

<?php

if(strlen($_GET['desde'])>0 and strlen($_GET['hasta'])>0){
$desde = $_GET['desde'];
$hasta = $_GET['hasta'];

$verDesde = date('d/m/Y', strtotime($desde));
$verHasta = date('d/m/Y', strtotime($hasta));
}else{
$desde = '1111-01-01';
$hasta = '9999-12-30';

$verDesde = '__/__/____';
$verHasta = '__/__/____';
}
require('../fpdf/fpdf.php');
require('conexion.php');




$pdf = new FPDF();
header("Content-Type: text/html; charset=iso-8859-1 ");
$pdf->AddPage();
  $pdf->SetFont('Arial', '', 10);
    $pdf->Image('../recursos/civil.jpg' , 130 ,5, 70 , 25,'jpg');
    $pdf->Cell(50, 10, 'Hoy: '.date('d-m-Y').'', 0);








$pdf->Ln();
   $pdf->Ln();

  $pdf->Cell(70, 8, '', 0);
  $pdf->Cell(100, 8, 'LISTADO DE EMERGENCIAS', 0,'C');
 $pdf->Ln();
 $pdf->Cell(60, 8, '', 0);
  $pdf->Cell(100, 8, 'Desde: '.$verDesde.' hasta: '.$verHasta, 0);
 $pdf->Ln(23);
   $pdf->SetFont('Arial', 'B', 8);





  //CONSULTA
  $productos = mysql_query("SELECT * FROM reporte WHERE fecha_reporte 
     BETWEEN '$desde' AND '$hasta' ");
      $item = 0;
 $totaluni = 0;
$totaldis = 0;
while($productos2 = mysql_fetch_array($productos)){
$item = $item+1;



$pdf->Cell(190, 8,'Clave:'.$productos2['id'], 1,1,'C');
    $pdf->Cell(190, 8,'Emergencia: '.$productos2['nombre'], 1,1,'');
$pdf->Cell (190, 8,'Descripción: '.$productos2['desc_emergencia'], 1,1,'');

$pdf->Cell(190, 8,'Nombre del reportante: ' 
.$productos2['nombre_reportante'],1,1,'');
$pdf->Cell(190, 8,'Teléfono: '.$productos2['telefono_reportante'], 1,1,'');
$pdf->Cell(190, 8,'Ubicación: ' .$productos2['ubicacion'],1,1,'');
    $pdf->Cell(190, 8,'Nivel de emergencia: ' 
.$productos2['nivel_emergencia'],1,1,'');
$pdf->Cell(190, 8, 'Fecha que se realizó esta emergencia: ' .date('d/m/Y', 
strtotime($productos2['fecha_reporte'])),1,1,'');
$pdf->Ln(10);
}


$pdf->Output('reporte.pdf','D');
?>

    
asked by Juan Lozano 17.06.2017 в 23:52
source

2 answers

2

In case anyone else happens to me, what I do is add this line in my connection to the BBDD:

mysqli_set_charset(connection,charset);

The connection is the first parameter and the encoding you want is the second one.

More information on link

    
answered by 18.06.2017 в 13:38
1

This is the simplest solution for FPDF to put accents:

 $this->Cell(30,10,utf8_decode("TECNOLÓGICO NACIONAL DE MÉXICO"),0,0,'C');
    
answered by 20.05.2018 в 21:53