使用TCPDF生成pdf会换行,求解决方法,谢谢

shenmdyw 2017-11-28 11:08:45
我生成pdf时中文会换行,如下图
html代码:
<div style="font-weight: bold;font-size:14;">    如贵方需要缴纳,请于<b style="text-decoration:underline;font-weight: bold;">{$date}</b>之前,将该款项转至我司专用来缴纳结果的帐号,同时注明数据号及用途为结果。若贵方指示不委托我方代缴或逾期未收到贵方指示的,我们将默认该<b style="text-decoration:underline;font-weight: bold;">数据贵方不维持</b>,并将该数据作结案处理,即就该案,<b style="text-decoration:underline;font-weight: bold;">贵方与我司委托关系结束;我方将不再有义务转达数据局的通知,请自行监控后续结果时限</b>。另,若贵方未能在指定期限内指示我司,或在超过我司指定期限后付款,则根据数据法规定,<b style="text-decoration:underline;font-weight: bold;">会产生滞纳金</b>,请知悉!</div>
当我去掉div中的其他标签时显示正常,在div标签中加入任何标签都会让中文换行,下面是php代码,
php代码:
 $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($title);
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
//echo PDF_HEADER_LOGO;exit;
// set default header data
//$pdf->SetHeaderData(PDF_HEADER_LOGO, 180);

// 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+13, 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/zho.php')) {
require_once(dirname(__FILE__).'/lang/zho.php');
$pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
$pdf->SetFont('stsongstdlight', '', 10);

// add a page
$pdf->AddPage();
// $yz="Public/Plus/tcpdf/examples/images/zhang.png";
//$yz_html = '<img src="' . $yz . '" />';
//$footer_image_file = 'Public/Plus/tcpdf/examples/images/footer.png';
// $footer_logo_html = '<img src="' . $footer_image_file . '" />';
//$pdf->serializeTCPDFtagParameters($data);
// writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
// writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=true)

// create some HTML content

//print_r($html);exit;
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
$height = $pdf->getY();
// $pdf->writeHTMLCell(50, 1, 130, $height-35, $yz_html, 0, 1, false, true, 'L', false);
//$pdf->writeHTMLCell(180, 1, 15, $height+16, $footer_logo_html, 0, 1, false, true, 'L', false);
//$footer_image_file = 'Public/Plus/tcpdf/000002.jpg';
//$footer_logo_html = '<img style="border:1px solid #ccc" src="' . $footer_image_file . '" />';
//$pdf->writeHTMLCell(200, 1, 15, $height, $footer_logo_html, 0, 1, false, true, 'L', false);
//Close and output PDF document
$pdf->Output('example_006.pdf', 'I');
...全文
984 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
shenmdyw 2019-11-07
  • 打赏
  • 举报
回复
引用 8 楼 蒋xx 的回复:
请问这个是怎么解决的呢?我这边的生成的pdf也会中文换行
只能是中间不加任何标签,没有解决方法,除非你在生成的时候先生成图片,然后插入进去
蒋xx 2019-11-04
  • 打赏
  • 举报
回复
请问这个是怎么解决的呢?我这边的生成的pdf也会中文换行
shenmdyw 2017-11-29
  • 打赏
  • 举报
回复
引用 4 楼 qq_34399969 的回复:
这个问题TCPDF无法很好解决的,我的解决方案是使用linux的工具wkhtmltopdf,网上有教程,直接安装使用好了,生成的pdf也比较小,很好用
谢谢,我网上找找看
shenmdyw 2017-11-29
  • 打赏
  • 举报
回复
引用 3 楼 xuzuning 的回复:
经测试,没有发现你说的现象
谢谢,回头我在下载试试看
老虎爱代码 2017-11-29
  • 打赏
  • 举报
回复
这个问题TCPDF无法很好解决的,我的解决方案是使用linux的工具wkhtmltopdf,网上有教程,直接安装使用好了,生成的pdf也比较小,很好用
xuzuning 2017-11-28
  • 打赏
  • 举报
回复
经测试,没有发现你说的现象
shenmdyw 2017-11-28
  • 打赏
  • 举报
回复
引用 1 楼 TottyAndBaty 的回复:
css里面加上 white-space: nowrap; 试试
谢谢回答,但还是不行
tottyandbaty 2017-11-28
  • 打赏
  • 举报
回复
css里面加上 white-space: nowrap; 试试

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧