Php 带特殊字符的TCPDF显示空PDF
我对TCPDF有问题,我不知道怎么做。我遵循了这个可以解决我同样问题的问题和答案: 但这并不能解决我的问题!我尝试过任何可能的解决方案,但每次打印空PDF或不打印任何内容都会超过执行php脚本的时间。 目标是从某个数据库获取数据并将其作为html表放入PDF,但在数据库中有一些带有重音的字符(èòù),当我得到它时,打印一个空PDF,当数据库中没有该字符时,PDF功能正常 我尝试过使用php utf8_encode函数,将字符编码从UTF-8更改为ISO-8859-1,但结果是一样的……这是我的初始代码:Php 带特殊字符的TCPDF显示空PDF,php,tcpdf,Php,Tcpdf,我对TCPDF有问题,我不知道怎么做。我遵循了这个可以解决我同样问题的问题和答案: 但这并不能解决我的问题!我尝试过任何可能的解决方案,但每次打印空PDF或不打印任何内容都会超过执行php脚本的时间。 目标是从某个数据库获取数据并将其作为html表放入PDF,但在数据库中有一些带有重音的字符(èòù),当我得到它时,打印一个空PDF,当数据库中没有该字符时,PDF功能正常 我尝试过使用php utf8_encode函数,将字符编码从UTF-8更改为ISO-8859-1,但结果是一样的……这是我的
$pdf = new MYPDF("L", PDF_UNIT, "A4", true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 001');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 001', PDF_HEADER_STRING, array(0, 64, 255), array(0, 64, 128));
$pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
$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);
if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
require_once(dirname(__FILE__) . '/lang/eng.php');
$pdf->setLanguageArray($l);
}
$pdf->setFontSubsetting(true);
$pdf->SetFont('dejavusans', '', 12, '', true);
$pdf->AddPage();
$pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));
/** WriteHTML ********* */
foreach ($selected as $sel) {
// Set some content to print
$field = $dbconn->listFields($sel);
$html .= "<b>$sel</b><br>";
$html .= "<table cellspacing=\"1\" cellpadding=\"0\" width=\"100%\"><thead><tr bgcolor=\"#F6AC00\" border=\"1px\">";
foreach ($field as $fd) {
$html .= "<th height=\"40px\" style=\"vertical-align:center\" align=\"center\"><b>$fd</b></th>";
}
$html .= "</tr></thead><tbody>";
$result = $dbconn->getRows($sel);
$color = true;
foreach ($result as $row) {
$rgb = $color ? "#FFFFFF" : "#E0E0FF";
$html .= "<tr nobr=\"true\" bgcolor=\"$rgb\" valign=\"center\">";
foreach ($row as $fd) {
// $width = strlen($fd) > 30 ? "400px" : "150px";
//$fd = $pdf->cleanString($fd);
$fd = utf8_encode($fd);
//$fd = html_entity_decode($fd, ENT_COMPAT | ENT_HTML401, "UTF-8");
$html .= "<td style=\"vertical-align:center\" align=\"center\" height=\"40px\">$fd</td>";
}
$html .= "</tr>";
$color = !$color;
}
$html .= "</tbody></table><br><br>";
}
//echo $html;
$pdf->writeHTML($html, true, false, false, false, '');
$pdf->Output("db_$dbname.pdf", 'I');
$pdf=新的MYPDF(“L”,pdf_单位,“A4”,真,“UTF-8”,假);
$pdf->SetCreator(pdf\u CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF示例001');
$pdf->SetSubject(“TCPDF教程”);
$pdf->SetKeywords('TCPDF,pdf,示例,测试,指南');
$pdf->SetHeaderData(pdf_标题_徽标,pdf_标题_徽标_宽度,pdf_标题_标题'001',pdf_标题_字符串,数组(0,64,255),数组(0,64,128));
$pdf->setFooterData(数组(0,64,0),数组(0,64,128));
$pdf->setHeaderFont(数组(pdf\u FONT\u NAME\u MAIN',pdf\u FONT\u SIZE\u MAIN));
$pdf->setFooterFont(数组(pdf字体名称数据),pdf字体大小数据);
$pdf->SetDefaultMonospacedFont(pdf\u字体\u等距);
$pdf->SetMargins(pdf\u MARGIN\u左、pdf\u MARGIN\u上、pdf\u MARGIN\u右);
$pdf->SetHeaderMargin(pdf\u MARGIN\u HEADER);
$pdf->SetFooterMargin(pdf\U MARGIN\U FOOTER);
$pdf->SetAutoPageBreak(TRUE,pdf\u MARGIN\u BOTTOM);
$pdf->setImageScale(pdf图像比例);
如果(@file_存在(dirname(_文件)。'/lang/eng.php')){
require_once(dirname(__文件)'/lang/eng.php');
$pdf->setLanguageArray($l);
}
$pdf->setFontSubsetting(真);
$pdf->SetFont('dejavusans','',12',,true);
$pdf->AddPage();
$pdf->setTextShadow(数组('enabled'=>true,'depth\u w'=>0.2,'depth\u h'=>0.2,'color'=>array(196196196196196),'opacity'=>1,'blend\u mode'=>Normal');
/**书面TML**********/
foreach($选择为$sel){
//设置一些要打印的内容
$field=$dbconn->listFields($sel);
$html.=“$sel
”;
$html.=”;
foreach($fd字段){
$html.=“$fd”;
}
$html.=”;
$result=$dbconn->getRows($sel);
$color=true;
foreach($结果为$行){
$rgb=$color?#FFFFFF:“#E0E0FF”;
$html.=”;
foreach(行为$fd){
//$width=strlen($fd)>30?“400px”:“150px”;
//$fd=$pdf->cleanString($fd);
$fd=utf8_编码($fd);
//$fd=html_entity_decode($fd,ENT_COMPAT | ENT_HTML401,“UTF-8”);
$html.=“$fd”;
}
$html.=”;
$color=!$color;
}
$html.=“
”;
}
//echo$html;
$pdf->writeHTML($html,true,false,false,false,”);
$pdf->Output(“db_u$dbname.pdf”,“I”);
请帮帮我!我绝望了