我使用TCPDF以PDF格式显示php文件并且它的工作真的很好,但是当我用č,ć,ž,š,đ字母说话时,我得到了白页......
在这种情况下,如果行[adresa]有这个字母,pdf页面没有结果,但如果没有字母,表格会以正确的方式显示。
我阅读了很多帖子,并尝试永久性,更改字体,启用编码,但我仍然有问题。
这是我的代码:
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');
答案 0 :(得分:0)
试试这个PHP代码:
$html. ='<tr>
<td>'.$row['cena'] .'</td>
<td>'.$row['adresa'] .'</td>
</tr>';
答案 1 :(得分:-1)
试试这个:
$html = ' <table class="table table-hover" width="100%" border="1" cellpadding="6" >
<thead>
<tr>
<th>title1</th>
<th>title2</th>
<th>title3</th>
<th>title4</th>
<th>title4</th>
<th>title5</th>
</tr>
</thead>
</table>';
// Print text using writeHTMLCell()
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);