php TCPDF使用writeHTML获得间距问题

2ul0zpep  于 2023-06-04  发布在  PHP
关注(0)|答案(1)|浏览(307)

我使用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');

由于某种原因,标题和文本之间有一个空格,如e

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

pgpifvop

pgpifvop1#

解决方案正如@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);

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

相关问题