Why Can't I Use č,ć,đ Charters In TCPDF Table?
Solution 1:
It will not work with times font. Our letters works with this font:
$pdf->SetFont('dejavusans', '', 11, '', true);
And UTF-8
EDIT After some time, I think that this is better:
$pdf->SetFont('freeserif', '', 11, '', true);
Solution 2:
I'm not sure if it will work, but try iconv
. I had to use it when I was making Japanese PDFs. I don't know what your encoding needs to be, but this is what I used:
$newtext = iconv("UTF-8", "SJIS", $oldtext);
Obviously change 'SJIS' to whatever encoding you are using.
EDIT
Just repeating what I said in the comments below, but hopefully it is easier to read up here:
Try changing the fourth constructor variable to TRUE
, so it uses UTF-8:
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'windows-1250', false);
⇓
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'windows-1250', false);
If that doesn't work, I don't know what to tell you :-/
EDIT (again)
Probably a silly question, but did you look at the examples?
http://www.tcpdf.org/examples/example_018.phps
Is there nothing there that can help you?
YET ANOTHER EDIT
Okay, hopefully this should do it:
<?php
require_once('tcpdf/config/lang/hrv.php');
require_once('tcpdf/tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'utf-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 061');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 061', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('freesans', '', 10);
// add a page
$pdf->AddPage();
//START OF DATA FOR PDF DOSJE
$ime = "šiš čevap";
$prezime = "čušpaiz";
$rodjenje = "čakardič";
$odjel = "četnik";
$radno_mjesto = "čaćijađ";
$poduzece = "čitluk";
$putovnica = "čošak";
$vozacka = "pićkica";
$html = <<<EOF
<!-- EXAMPLE OF CSS STYLE -->
<table width="100%" style="padding:3px;">
<tr>
<td>
<table border="1" style="border:1px solid grey; width:60%;">
<tr>
<td rowspan="3">
<p style="margin-top:-38px;">POSLODAVAC:</p>
</td>
<td>
Ime firme
</td>
</tr>
<tr>
<td>
adresa firme
</td>
</tr>
<tr>
<td>
oib firme
</td>
</tr>
</table>
<br>
<table border="1" style="border:1px solid #dddddd; width:60%;">
<tr>
<td>
RADNIK:
</td>
<td>
$ime $prezime
</td>
</tr>
<tr>
<td>
Oib
</td>
<td>
$rodjenje
</td>
</tr>
<tr>
<td>
Spol
</td>
<td>
$odjel
</td>
</tr>
<tr>
<td>
Dan, mjesec i godina rođenja
</td>
<td>
$radno_mjesto
</td>
</tr>
<tr>
<td>
Državljanstvo
</td>
<td>
$radno_mjesto
</td>
</tr>
</table>
<br>
</td>
</tr>
</table>
EOF;
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// reset pointer to the last page
$pdf->lastPage();
//Close and output PDF document
$pdf->Output('example_061.pdf', 'I');
?>
If you are using values from your 1250-encoded database, you will need to convert them like this:
$db = mysql_connect('localhost', 'user', 'password');
mysql_select_db('databasename', $db);
mysql_set_charset("cp1250");
$query = mysql_query("SELECT * FROM `yourtable`");
while ($row = mysql_fetch_assoc($query)) {
$converted_value = iconv("windows-1250", "utf-8", $row['column_name']);
}
I made a test table with 1250 collation in my own database, and used the words you supplied. This worked for me. Let me know if it helps!
Solution 3:
try to use mPDF, it is more convinient and clear to understand (mPDF) Expamle:
require(LIBRARY . "/MPDF54/mpdf.php");
$mpdf=new mPDF('c','A4-L','','',10,10,20,15,5,5, 'L');
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0;
$header = $view->render('header.phtml');
$mpdf->SetHTMLHeader($header);
$footer = $view->render('footer.phtml');
$mpdf->SetHTMLFooter($footer);
$view->client_info = $client_info[0];
$view->info = $info;
$view->lots = $lots;
$html = $view->render('invoice.phtml');
$mpdf->WriteHTML($html,2);
$mpdf->Output("bidder_$id.pdf",'I');
exit;
Solution 4:
Can't you just use the codes like this:
č = č
ć = ć
đ = đ
?
I personaly also have better experiences with mPDF.
Solution 5:
I have same problem, some tips:
Like in other answers check your font, it must be unicode...
Then, check your encoding :
You can do it with : mb_detect_encoding.
Like this :
$x=$row['adresa']; // $x=test
echo mb_detect_encoding($x);
echo $x;
end result will be,etc. : UTF-8 test
If is not Utf-8 Tcpdf will show blank page.
Post a Comment for "Why Can't I Use č,ć,đ Charters In TCPDF Table?"