簡體   English   中英

TCPDF - DIV 前后顯示額外空間

[英]TCPDF - DIV is showing extra space before and after

我正在使用 TCPDF 以 pdf 格式轉換長格式。 我的html結構是這樣的:

<table cellspacing='0' cellpadding='0' border='0'>
  <tr>
      <td>
          <div style="page-break-inside: avoid;"> ..one more table ..</div>
      </td>
  </tr>
</table>

但是在PDF的輸出中,div前后有一些額外的空間(大約20px)。 當我刪除那個<div>它看起來很完美。 但我不能刪除它。 我無法找出解決方案。

任何建議將不勝感激。 謝謝

我知道這是舊的,但看看setHtmlVSpace類。

<td>內的空間被解釋。 您可以編寫這樣的代碼來刪除空格:

<table cellspacing='0' cellpadding='0' border='0'>
  <tr>
      <td><div style="page-break-inside: avoid;"> ..one more table ..</div></td>
  </tr>
</table>

如果您使用 Twig 或 Smarty 等模板語言,則有一些解決方案可以放置在您的代碼周圍:
樹枝: {% spaceless %} https://twig.symfony.com/doc/2.x/tags/spaceless.html
Smarty : {strip} http://www.smarty.net/docsv2/fr/language.function.strip.tpl

要為 HTML 標簽設置垂直空間,在這種情況下,'div' 使用:

$tagvs = {'div' => [{'h' => 0, 'n' => 0}, {'h' => 0, 'n' => 0}]}
$pdf->setHtmlVSpace($tagvs);

$tagvs:標簽數組和相對垂直空間。

[{'h' => 0, 'n' => 0}, {'h' => 0, 'n' => 0}]:第一個用於開始標簽'div',第二個用於結束標簽'/div' .

'h' : 垂直空間單位

'n' : 要添加的數字空格

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM