TCPDF 使用 writeHTML 遇到间距问题

edd*_*ddy 6 php tcpdf

我正在使用 html 创建 pdf。下面是我的代码:

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);


$pdf->SetMargins(15, 20, 14, 0);
$pdf->SetAutoPageBreak(TRUE, 0);
$pdf->setCellPaddings(0,0,0,0);
$pdf->setFooterMargin(0);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

// add a page
$pdf->AddPage();

    $html = '
    <div style="background-color: #f8f8f8;">

    <div style="font-size: 24px; color: #333; font-weight: 600; font-family:Arial,Helvetica,sans-serif;">Example</div>

    <p style="color: #828282; font-size: 14px; font-family: sans-serif;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
    Lorem Ipsum has been the industry standard dummy text ever since the 1500s, 
    when an unknown printer took a galley of type and scrambled it to make a type
    specimen book. It has survived not only five centuries, but also the leap 
    into electronic typesetting, remaining essentially unchanged. It was popularised 
    in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
    and more recently with desktop publishing software like Aldus PageMaker including 
    versions of Lorem Ipsum.</p>
  </div>';

$pdf->writeHTML($html, false, false, true, false, '');

$pdf->Output('example_001.pdf', 'I');
Run Code Online (Sandbox Code Playgroud)

由于某种原因,标题和文本之间有一个空格,如您所见在此输入图像描述

另外,每当我添加行高样式以在段落中的行之间留出一些空间时,它只会留下更多的间隙。

Dji*_*del 3

解决方案正如@Frankich 评论的那样:

$tagvs = [
    'div' => [
        0 => ['h' => 0, 'n' => 0],
        1 => ['h' => 0, 'n' => 0]
    ],
    'p' => [
        0 => ['h' => 0, 'n' => 0],
        1 => ['h' => 0, 'n' => 0]
    ]
];
$pdf->setHtmlVSpace($tagvs);
Run Code Online (Sandbox Code Playgroud)

文档: https ://tcpdf.org/docs/srcdoc/TCPDF/classes-TCPDF/#method_setHtmlVSpace