2

i have a problem with TCPDF and i don't know how to do. I have followed this question and answer that could be resolve my same problem: question

But this not resolve my problem! i have tried anything solutions possible but every time print a empty PDF or not print nothing exceed the time of execution of a script php. The goal is get data from some database and put them into PDF as a html table, but in the database there are some character with accent (è à ò ù), when i get it print a empty PDF and when this character there are not in the database, the PDF function normally.

I have tried with function php utf8_encode, changing character encodind from UTF-8 to ISO-8859-1 but nothing, the result is the same...This is my initial code:

$pdf = new MYPDF("L", PDF_UNIT, "A4", true, 'UTF-8', false);


$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 001');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');


$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 001', PDF_HEADER_STRING, array(0, 64, 255), array(0, 64, 128));
$pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));


$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));


$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);


$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);


$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);


$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);


if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
    require_once(dirname(__FILE__) . '/lang/eng.php');
    $pdf->setLanguageArray($l);
}

$pdf->setFontSubsetting(true);


$pdf->SetFont('dejavusans', '', 12, '', true);

$pdf->AddPage();

$pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));

/** WriteHTML ********* */
foreach ($selected as $sel) {
    // Set some content to print
    $field = $dbconn->listFields($sel);
    $html .= "<b>$sel</b><br>";
    $html .= "<table cellspacing=\"1\" cellpadding=\"0\" width=\"100%\"><thead><tr bgcolor=\"#F6AC00\" border=\"1px\">";
    foreach ($field as $fd) {
        $html .= "<th height=\"40px\" style=\"vertical-align:center\" align=\"center\"><b>$fd</b></th>";
    }
    $html .= "</tr></thead><tbody>";
    $result = $dbconn->getRows($sel);
    $color = true;

    foreach ($result as $row) {
        $rgb = $color ? "#FFFFFF" : "#E0E0FF";
        $html .= "<tr nobr=\"true\" bgcolor=\"$rgb\" valign=\"center\">";
        foreach ($row as $fd) {
            // $width = strlen($fd) > 30 ? "400px" : "150px";
            //$fd = $pdf->cleanString($fd);
            $fd = utf8_encode($fd);
            //$fd = html_entity_decode($fd, ENT_COMPAT | ENT_HTML401, "UTF-8");
            $html .= "<td style=\"vertical-align:center\" align=\"center\" height=\"40px\">$fd</td>";
        }
        $html .= "</tr>";
        $color = !$color;
    }

    $html .= "</tbody></table><br><br>";
}
//echo $html;
$pdf->writeHTML($html, true, false, false, false, '');

$pdf->Output("db_$dbname.pdf", 'I');

Please, help me! i am desperate!

Community
  • 1
  • 1
Riccardo
  • 101
  • 8

0 Answers0