title: TCPDF Overlapping Tables
body: <p>I just started working with a new web app in Symfony, which one of it's functions is to print receipts using TCPDF. It works fine, but every once in a while when a client wants to put one of the field really big(in this case the Observation field), it overlaps with other tables, like the following image:</p>
  
  <p><a href="https://i.imgur.com/LM3CtRQ.png" rel="nofollow noreferrer"><img src="https://i.imgur.com/LM3CtRQ.png" alt="Receipt screenshot"></a></p>
  
  <p>I tried to cut as much of the code as possible to show you and not be so confused. </p>
  
  <p>But the most relevant piece of code (I think) is this one:</p>
  
  <pre><code>if($showObservacoesProdutos){
                  if($value-&gt;getObservacoes() != ''){
                      //ERROR!!!!!!!!!!!!! IT'S HERE THAT'S OVERLAPPING WITH EVERYTHING!!!!!!!!!!!!!1
                      $htmlProdutos[$count] .= '
                          &lt;tr '.$line.'&gt;
                              &lt;td colspan="7" style="text-align: justify; font-size: 22px;"&gt;&lt;b&gt;'.__("Observações").':&lt;/b&gt; '.nl2br($value-&gt;getObservacoes()).'&lt;/td&gt;
                          &lt;/tr&gt;';
                  }
              }
  
              $htmlProdutos[$count] .= '&lt;/table&gt;';
  
              $flag++;
  
              ($key+1 == sizeof($this-&gt;produtos)) ? $height=187 : $height=259;
  
              if($documento instanceof CmrFacturas &amp;&amp; $key+1 == sizeof($this-&gt;produtos)){
                  if($sf_user-&gt;getAttribute('id_pais_empresa') == InfPaises::ID_PORTUGAL){
                      $htmlProdutos[$count] .='&lt;div style="padding-top: 5px; font-style: italic; font-weight: bold;"&gt;'.__("Os artigos / serviços foram colocados à disposição do adquirente na data").' '.$documento-&gt;getDataEmissao().'. ('.__("Alínea F nº5 artº 36 CIVA").').&lt;/div&gt;';
                  }                    
              }
  
              $pdf-&gt;writeHTMLCell(190, '', '', $pdf-&gt;getY(), $htmlProdutos[$count], 0, 0, 0, true, 'L', true);
  
              $pdf-&gt;Ln();
  
              if($pdf-&gt;getY() &gt; $height){
                  $pdf-&gt;AddPage();
                  $count++;
                  $flag = 0;
              }
  </code></pre>
  
  <p>Since this is in Portuguese, the field that is overlapping is called <code>Observações</code>. </p>
  
  <p>Any kind of help will be appreciated.</p>
  
  <p>EDIT: With spaces, the problem doesn't look so serious. I think now the only problem is that it is overlapping with the header. I also traded the image above to correspond with a receipt with spaces.</p>
  
  <p>EDIT2: I got an idea but no idea on how to execute it. Maybe the problems lies within the html disposition. Instead of putting the <code>Observações</code> part in a cell inside a table, maybe I can put it inside another html container, except I already tried using <code>divs</code> and <code>p</code>, but it still overlaps. Maybe somebody else has another idea.</p>
  
  <p>EDIT3: If I reduce the size of the text of the <code>Observações</code> part, it stops overlapping, but if I inscrese the number of lines in one of the products, it starts to overlap again.</p>