Richa
Richa

Reputation: 4270

TCPDF - DIV is showing extra space before and after

I am converting a long form in pdf using TCPDF. My structure of html is like this:

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

But in output of PDF, there is some extra space (about 20px) before and after div. When I remove that <div> it looks perfect. But I cant remove that. I am unable to figure out the solution.

Any suggestion would be appreciated. Thanks

Upvotes: 3

Views: 8032

Answers (3)

SumitK
SumitK

Reputation: 215

To set the vertical spaces for HTML tags, in this case div use:

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

$tagvs: Array of tags and relative vertical spaces.

[{'h' => 0, 'n' => 0}, {'h' => 0, 'n' => 0}]: First for opening tag 'div', Second for closing tag '/div'.

'h' : Vertical space unit

'n' : Number spaces to add

Upvotes: 5

Emilien Baudet
Emilien Baudet

Reputation: 458

The space inside your block <td> is interpreted. You can write your code like this to remove the space :

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

If you use a templating language as Twig or Smarty, there are some solutions to put arround your code :
Twig : {% spaceless %} https://twig.symfony.com/doc/2.x/tags/spaceless.html
Smarty : {strip} http://www.smarty.net/docsv2/fr/language.function.strip.tpl

Upvotes: 6

tsg
tsg

Reputation: 205

I know this is old, but look at the setHtmlVSpace class.

Upvotes: 6

Related Questions