为什么我不能在TCPDF表中使用?,?,?宪章? [英] Why can't I use č,ć,đ charters in TCPDF table?
问题描述
我为我的网站建立一个tcpdf文件,在那个tcpdf文件中,它是一个包含一些数据的表格,但是我不能让这个章程正常工作。对于编码,我使用的是windows-1250。
特许女巫不工作:č,ć,đ。我已经尝试过使用utf-8,但是仍然没有注意到这个章程是否存在tcpdf的错误?
这里是我的php:
<?php
require_once('tcpdf_files / config / lang / hrv.php');
require_once('tcpdf_files / tcpdf.php');
//创建新的PDF文档
$ pdf =新的TCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,false,'windows-1250',false);
//设置文档信息
$ pdf-> SetCreator(PDF_CREATOR);
$ pdf-> SetAuthor('Nicola Asuni');
$ pdf-> SetTitle('TCPDF Example 061');
$ pdf-> SetSubject('TCPDF Tutorial');
$ pdf-> SetKeywords('TCPDF,PDF,example,test,guide');
//设置默认标题数据
$ pdf-> SetHeaderData(PDF_HEADER_LOGO,PDF_HEADER_LOGO_WIDTH,PDF_HEADER_TITLE。'061',PDF_HEADER_STRING);
//设置页眉和页脚字体
$ pdf-> setHeaderFont(Array(PDF_FONT_NAME_MAIN,'',PDF_FONT_SIZE_MAIN));
$ pdf-> setFooterFont(Array(PDF_FONT_NAME_DATA,'',PDF_FONT_SIZE_DATA));
//设置默认等宽字体
$ pdf-> SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//设定保证金
$ pdf-> SetMargins(PDF_MARGIN_LEFT,PDF_MARGIN_TOP,PDF_MARGIN_RIGHT);
$ pdf-> SetHeaderMargin(PDF_MARGIN_HEADER);
$ pdf-> SetFooterMargin(PDF_MARGIN_FOOTER);
//设置自动分页符
$ pdf-> SetAutoPageBreak(TRUE,PDF_MARGIN_BOTTOM);
//设置图像比例因子
$ pdf-> setImageScale(PDF_IMAGE_SCALE_RATIO);
//设置一些依赖语言的字符串
$ pdf-> setLanguageArray($ l);
// ---------------------------------------- -----------------
//设置字体
$ pdf-> SetFont('times','',10);
//添加页面
$ pdf-> AddPage();
//启动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 =< <! - CSS样式示例 - >
< table width =100%style =padding:3px;>
< tr>
< td>
< table border =1style =border:1px solid gray; 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 =1style =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 godinarođenja
< / td>
< td>
$ radno_mjesto
< / td>
< / tr>
< tr>
< td>
Državljanstvo
< / td>
< td>
$ radno_mjesto
< / td>
< / tr>
< / table>< br>
EOF;
//输出HTML内容
$ pdf-> writeHTML($ html,true,false,true,false,'');
//重置指向最后一页的指针
$ pdf-> lastPage();
//关闭并输出PDF文档
$ pdf->输出('example_061.pdf','I');
我不确定它是否可行,但试试 iconv
。我在制作日文PDF时不得不使用它。我不知道你的编码需要什么,但这是我用过的:
$ newtext = iconv(UTF -8,SJIS,$ oldtext);
显然可以将'SJIS'更改为您使用的任何编码。
编辑
只需重复我在下面的评论中所说的内容,但希望这里更容易阅读:
尝试将第四个构造函数变量更改为 TRUE
,以便使用UTF-8:
$ pdf =新的TCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,false,'windows-1250',false);
$ pdf =新的TCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,'windows-1250',false);
如果这不起作用,我不知道该告诉你什么: - /
再次编辑
可能是一个愚蠢的问题,但是您看过例子?
http:// www。 tcpdf.org/examples/example_018.phps
有没有什么可以帮到你的?
$ p><?php
require_once('tcpdf / config / lang / hrv.php');
require_once('tcpdf / tcpdf.php');
//创建新的PDF文档
$ pdf =新的TCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,'utf-8',false);
//设置文档信息
$ pdf-> SetCreator(PDF_CREATOR);
$ pdf-> SetAuthor('Nicola Asuni');
$ pdf-> SetTitle('TCPDF Example 061');
$ pdf-> SetSubject('TCPDF Tutorial');
$ pdf-> SetKeywords('TCPDF,PDF,example,test,guide');
//设置默认标题数据
$ pdf-> SetHeaderData(PDF_HEADER_LOGO,PDF_HEADER_LOGO_WIDTH,PDF_HEADER_TITLE。'061',PDF_HEADER_STRING);
//设置页眉和页脚字体
$ pdf-> setHeaderFont(Array(PDF_FONT_NAME_MAIN,'',PDF_FONT_SIZE_MAIN));
$ pdf-> setFooterFont(Array(PDF_FONT_NAME_DATA,'',PDF_FONT_SIZE_DATA));
//设置默认等宽字体
$ pdf-> SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//设定保证金
$ pdf-> SetMargins(PDF_MARGIN_LEFT,PDF_MARGIN_TOP,PDF_MARGIN_RIGHT);
$ pdf-> SetHeaderMargin(PDF_MARGIN_HEADER);
$ pdf-> SetFooterMargin(PDF_MARGIN_FOOTER);
//设置自动分页符
$ pdf-> SetAutoPageBreak(TRUE,PDF_MARGIN_BOTTOM);
//设置图像比例因子
$ pdf-> setImageScale(PDF_IMAGE_SCALE_RATIO);
//设置一些依赖语言的字符串
$ pdf-> setLanguageArray($ l);
// ---------------------------------------- -----------------
//设置字体
$ pdf-> SetFont('freesans','',10);
//添加页面
$ pdf-> AddPage();
//开始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
<! - CSS样式示例 - >
< table width =100%style =padding:3px;>
< tr>
< td>
< table border =1style =border:1px solid gray; 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 =1style =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 godinarođenja
< / td>
< td>
$ radno_mjesto
< / td>
< / tr>
< tr>
< td>
Državljanstvo
< / td>
< td>
$ radno_mjesto
< / td>
< / tr>
< / table>
< br>
< / td>
< / tr>
< / table>
EOF;
//输出HTML内容
$ pdf-> writeHTML($ html,true,false,true,false,'');
//重置指向最后一页的指针
$ pdf-> lastPage();
//关闭并输出PDF文档
$ pdf->输出('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']);
$ b $ p
$ b我在我自己的数据库中用1250排序规则做了一个测试表,你提供的话。这对我有效。让我知道它是否有用!
I'm building a tcpdf file for my web site, in that tcpdf file ther is a table with some data, But I cant get this charters to work properly. for encoding I'm using windows-1250.
The charters witch are not working : č,ć,đ. I have tried with utf-8 but still not geting this charters is there something wrong with tcpdf?
here is my 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');
解决方案 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!
这篇关于为什么我不能在TCPDF表中使用?,?,?宪章?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!