【问题标题】:TCPDF don't show č,ć,ž,š,đ from mysql only blank pageTCPDF 不显示 č,ć,ž,š,đ 从 mysql 仅空白页
【发布时间】: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');

【问题讨论】:

    标签: php mysql utf-8 tcpdf


    【解决方案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);   
    

    【讨论】:

      【解决方案2】:

      为 php 代码试试这个:

      $html. ='<tr>
        <td>'.$row['cena'] .'</td>
        <td>'.$row['adresa'] .'</td>
       </tr>';
      

      【讨论】:

      • Hi and tnx :) 问题是在 html 中显示 php 值,因为如果我删除
      • 这项工作,但不适用于我在标题中写的字母:
        Cena ' 。 $行['cena']。 '
        Adresa ' 。 $行['adresa']。 '
      猜你喜欢
      • 1970-01-01
      • 2012-01-19
      • 2020-03-30
      • 1970-01-01
      • 1970-01-01
      • 2014-06-29
      • 2019-10-29
      • 1970-01-01
      • 2014-07-11
      相关资源
      最近更新 更多