Reputation: 23
I'm newbie using TCPDF library and I'm having problems with Write
and MultiCell
functions. I don't know why sometimes TCPDF only prints the first character of the string given.
This is how it looks my print_r($row)
Array(
[0] =>
[codDefinitivo] =>
[1] => Best Spot
[seccion] => Best Spot
[2] =>
[colaboradora] =>
[3] => KELER
[marca] => KELER
[4] => KELER
[anunciante] => KELER
[5] => DIMENSION
[inscrito_pr] => DIMENSION
[6] => ARZAK Y KELER, HISTORIAS PARALELAS
[titulo] => ARZAK Y KELER, HISTORIAS PARALELAS
[7] => DIMENSION
[agencia] => DIMENSION
[8] => Bebidas alcohólicas
[categoria] => Bebidas alcohólicas
[9] => Nacer en Donostia, la pasión por el sabor y una apuesta por la intensidad son algunas de las características que Arzak y Keler tienen en común.? El spot crea un paralelismo entre la vida de Arzak y la de Keler como referentes donostiarras del sabor y de la intensidad. Esta historia, puede ser narrada igualmente por keler, Y ese es el juego de la historia, el paralelismo entre los dos protagonista, la confusión, el ?de quien hablo?, de Juan Mari Arzak.. o de KELER.
[descripcion] => Nacer en Donostia, la pasión por el sabor y una apuesta por la intensidad son algunas de las características que Arzak y Keler tienen en común.? El spot crea un paralelismo entre la vida de Arzak y la de Keler como referentes donostiarras del sabor y de la intensidad. Esta historia, puede ser narrada igualmente por keler, Y ese es el juego de la historia, el paralelismo entre los dos protagonista, la confusión, el ?de quien hablo?, de Juan Mari Arzak.. o de KELER.)
When I use the $row['seccion']
or the $row['descripcion']
the result is only the first character of both strings... I don't know what I'm missing.
This is how I coded the Write
and MultiCell
functions
$pdf->MultiCell (66, 10, $row['descripcion'], 0, 'L', false, 1, 75, 38, true, 0, false, true, 0, 'T', false);
$pdf->Write(2, $row['seccion'], '', 0, 'L', true, 0, false, false, 0);
If I copy the content $row[descripccion]
into the MultiCell
function TCPDF outputs it correctly
$pdf->MultiCell (67, 10, "Nacer en Donostia, la pasión por el sabor y una apuesta por la intensidad son algunas de las características que Arzak y Keler tienen en común.? El spot crea un paralelismo entre la vida de Arzak y la de Keler como referentes donostiarras del sabor y de la intensidad. Esta historia, puede ser narrada igualmente por keler, Y ese es el juego de la historia, el paralelismo entre los dos protagonista, la confusión, el ?de quien hablo?, de Juan Mari Arzak.. o de KELER.", 0, 'L', false, 1, 75, 38, true, 0, false, true, 0, 'T', false);
The php script is the following [...]
$result = mysql_query($sql,$link_kobal);
while($row = mysql_fetch_array($result))
{
$pdf->SetFont($fontNameTitol, 'B', $tamanyFont);
$pdf->Write(2, $row['seccion'], '', 0, 'L', true, 0, false, false, 0);
$pdf->SetFont('helvetica', '', 8);
// Descripció
$pdf->SetXY(75, 35);
$pdf->SetFont('helvetica', 'B', 8);
$pdf->Write(2, 'Descripción', '', 0, 'L', true, 0, false, false, 0);
$pdf->SetFont('helvetica', '', 8);
$pdf->MultiCell (67, 10, $row['descripcion'], 0, 'L', false, 1, 75, 38, true, 4, false, true, 0, 'T', false);
}
Thanks in advice!
Upvotes: 0
Views: 669
Reputation: 171
In my case TCPDF reacted the same way when I passed invalid UTF-8 string to it. Using mb_substr($text, 0, $max_length, 'UTF-8') instead of mb_substr($text, 0, $max_length) solved the issue. I'd suspect your solution (utf8_encode) intermittently fixes the error that occurred earlier in the code.
Upvotes: 0
Reputation: 23
Hi everyone and thanks for you help!
I solved my issue. Now the MultiCell or Write function of TCPDF is showing all the data. The solution was to add the utf8_encode function that way: $pdf->MultiCell (67, 10, utf8_encode($row['descripcion']), 0, 'L', false, 1, 75, 38, true, 4, false, true, 0, 'T', false);
Hope is usefull for somebody!
Upvotes: 1