TCPDF html呈现不缩进

问题描述 投票:0回答:1

我正在尝试使用来自我的数据库的TCPDF显示数据,这些数据是专门缩进的。

我使用writeHTMLCell来做到这一点。

EG :

“这应该缩进为: - 第一颗子弹 - 第二个 然后是示例的结尾。“

但是,当然,它将文本呈现在一行上。

有谁知道我怎么能正确渲染文字?

非常感谢你 !

html indentation tcpdf
1个回答
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将包含以下单元格:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.