【发布时间】:2014-01-13 09:21:48
【问题描述】:
我使用 TCPDF 在 PDF 中显示 php 文件,它工作得很好,但是当我有 č、ć、ž、š、đ 字母的单词时,我得到了白页...
在这种情况下,如果 row[adresa] 有这些字母,则在 pdf 页面中没有结果,但如果没有任何字母,则表格以正确的方式显示。
我阅读了很多帖子,并尝试了everuthing,更改字体,启用编码,但我仍然有问题。
这是我的代码:
require_once('tcpdf_include.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('Agencija za nekretnine');
$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.' 048', 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 (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('freesans');
// add a page
$pdf->AddPage();
$pdf->Write(0, '', '', 0, 'L', true, 0, false, false, 0);
$pdf->SetFont('freesans');
// -----------------------------------------------------------------------------
$con=mysqli_connect("localhost","root","","senzal");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id =$_POST['ajde'];//post from my index page
$result = mysqli_query($con,"SELECT * FROM stan where id=$id ");
while($row = mysqli_fetch_array($result))
{
// NON-BREAKING TABLE (nobr="true")
$tbl = <<<EOD
<table border="1" cellpadding="2" cellspacing="2" nobr="true">
<tr>
<th colspan="3" align="center">Nekretnina broj: $row[id] </th>
</tr>
<tr>
<td>Cena:</td>
<td>$row[cena]</td>
</tr>
<tr>
<td>Adresa</td>
<td>$row[adresa]</td> // this rows made a problem
</tr>
<tr>
<td>3-1</td>
<td>3-2</td>
<td>3-3</td>
</tr>
</table>
EOD;
}
$pdf->writeHTML($tbl, true, false, false, false, '');
// -----------------------------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_048.pdf', 'I');
【问题讨论】: