我试图用我的数据库中的TCPDF显示数据,这些数据是专门缩进的。
我使用writeHTMLCell来执行此操作。
e.g。 :
"这应该缩进:
- 第一个子弹
- 第二个
然后是示例的结尾。"
但当然,它会将文字呈现在一行上。
有谁知道我如何正确渲染文字?
非常感谢!
答案 0 :(得分:1)
使用HTML预格式化文本要求您使用<pre>
。这是一个例子:
This should be indented as so:
- First bullet
- Second one
Then the end of the example.
<pre>
This should be indented as so:
- First bullet
- Second one
Then the end of the example.
</pre>
将<pre>
标签与预先格式化的文本块一起使用可以达到您想要的效果。预格式化文本默认为等宽字体,可以使用$pdf->SetDefaultMonospacedFont()
进行更改。以下是包含和不包含<pre>
的示例:
<?php
require_once('tcpdf_include.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->AddPage();
$text_sample = 'This should be indented as so:
- First bullet
- Second one
Then the end of the example.';
$y = $pdf->getY();
$pdf->SetDefaultMonospacedFont('helvetica');
$pdf->SetFont('helvetica', '', 14, '', true);
$pdf->SetFillColor(255, 255, 255);
$pdf->SetTextColor(255, 92, 92);
$pdf->writeHTMLCell(190, '', '', $y, $text_sample, 1, 0, 1, true, 'J', true);
$pdf->SetTextColor(53,183,41);
$pdf->writeHTMLCell(190, '', '', $y+20, '<pre>'.$text_sample.'</pre>', 1, 1, 1, true, 'J', true);
$pdf->Output('example.pdf', 'I');
PDF将包含以下单元格: