我为什么不能在TCPDF表中使用č,ć,ć宪章?
作者:互联网
我正在为我的网站构建一个tcpdf文件,因为tcpdf文件是一个包含一些数据的表,但我无法使此章程正常工作.用于编码,我使用的是Windows-1250.
宪章女巫不工作:č,ć,đ.我已经尝试过使用utf-8,但仍然无法获得此章程,tcpdf是否有问题?
这是我的PHP:
<?php
require_once('tcpdf_files/config/lang/hrv.php');
require_once('tcpdf_files/tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'windows-1250', 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('times', '', 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>
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');
解决方法:
我不确定是否可以使用,但请尝试使用iconv.制作日文PDF时必须使用它.我不知道您的编码需要是什么,但这是我使用的:
$newtext = iconv("UTF-8", "SJIS", $oldtext);
显然,将“ SJIS”更改为您使用的任何编码.
编辑
只是重复我在下面的评论中所说的,但是希望可以在这里更容易阅读:
尝试将第四个构造函数变量更改为TRUE,因此它使用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);
如果那行不通,我不知道该告诉你什么:-/
再次编辑
可能是一个愚蠢的问题,但您是否看过这些例子?
http://www.tcpdf.org/examples/example_018.phps
那里没有什么可以帮助您的吗?
还需要编辑
好的,希望这可以做到:
<?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');
?>
如果您正在使用1250编码数据库中的值,则需要像下面这样转换它们:
$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']);
}
我在自己的数据库中用1250排序规则创建了一个测试表,并使用了您提供的单词.这对我有用.让我知道是否有帮助!
标签:tcpdf,html,php 来源: https://codeday.me/bug/20191101/1982629.html