title: TCPDF table header apply a different margin on next page + closee table before page break
body: <p>The code used to print the pdf is as follows:</p>
  
  <p><strong>PdfController</strong> :</p>
  
  <pre><code>/**
   * @Route("/{id}", name="api_article_pdf", methods={"GET"})
   */
  public function gepdf2html($id)
  {
  
      // create new PDF document
      $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  
  // set document information
      $pdf-&gt;SetCreator(PDF_CREATOR);
      $pdf-&gt;SetAuthor('OPAL TPE');
      $pdf-&gt;SetTitle('Articles');
      $pdf-&gt;SetSubject('TCPDF Tutorial');
      $pdf-&gt;SetKeywords('TCPDF, PDF, example, test, guide');
  
  // set default header data
      $pdf-&gt;SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 001', PDF_HEADER_STRING, array(0, 64, 255), array(0, 64, 128));
      $pdf-&gt;setFooterData(array(0, 64, 0), array(0, 64, 128));
  
  // set header and footer fonts
      $pdf-&gt;setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
      $pdf-&gt;setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  
   // set default monospaced font
      $pdf-&gt;SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  
  // set margins
      $pdf-&gt;SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
      $pdf-&gt;SetHeaderMargin(PDF_MARGIN_HEADER);
      $pdf-&gt;SetFooterMargin(PDF_MARGIN_FOOTER);
  
   // set auto page breaks
      $pdf-&gt;SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  
  // set image scale factor
      $pdf-&gt;setImageScale(PDF_IMAGE_SCALE_RATIO);
  
  
   // ---------------------------------------------------------
  
   // set default font subsetting mode
      $pdf-&gt;setFontSubsetting(true);
  
  // Set font
  // dejavusans is a UTF-8 Unicode font, if you only need to
  // print standard ASCII chars, you can use core fonts like
  // helvetica or times to reduce file size.
      $pdf-&gt;SetFont('dejavusans', '', 14, '', true);
  
  // Add a page
  // This method has several options, check the source code documentation for more information.
      $pdf-&gt;AddPage();
  
  // set text shadow effect
      $pdf-&gt;setTextShadow(array('enabled' =&gt; true, 'depth_w' =&gt; 0.2, 'depth_h' =&gt; 0.2, 'color' =&gt; array(196, 196, 196), 'opacity' =&gt; 1, 'blend_mode' =&gt; 'Normal'));
  // $id document
      $id_d= substr($id, 0,-7);
      $id=$id_d-5;
      $id=$id/7;
  // Set some content to print
  
      // $em = $this-&gt;getDoctrine()-&gt;getManager();
      $query2= $this-&gt;em-&gt;createQuery('SELECT 
                                  a.libelle as libelle,
                                  a.description as desc,
                                  a.prixVenteHt as prixHt,
                                  a.prixVenteTtc as prixTtc
                                  FROM
                                  App\Entity\Dossier\Article as a
                                  WHERE a.id = :id
                                  ');
      $query2-&gt;setParameter("id", $id);
      $data = $query2-&gt;getResult();
  
      $html = $this-&gt;renderView('test.html.twig',
          ['data' =&gt; $data]);
  
  // Print text using writeHTMLCell()
      $pdf-&gt;writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
  
  // ---------------------------------------------------------
  
  // Close and output PDF document
  // This method has several options, check the source code documentation for more information.
      return $pdf-&gt;Output('example_001.pdf', 'I');
  </code></pre>
  
  <p>and my <strong>test.html.twig</strong> code :</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;table nobr="true" cellspacing="0" cellpadding="1" border="1"&gt;
      &lt;thead&gt;
          &lt;tr style="background-color:silver;"&gt;&lt;th&gt;Libelle&lt;/th&gt;
              &lt;td&gt;Description&lt;/td&gt;
              &lt;td&gt;Prix V HT&lt;/td&gt;
              &lt;td&gt;Prix V TTC&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
  
      &lt;tbody&gt;
      {% for d in data %}&lt;br&gt;
          &lt;tr&gt;
              &lt;td&gt;{{ d.libelle }}&lt;/td&gt;
              &lt;td&gt;{{ d.desc }}&lt;/td&gt;
              &lt;td&gt;{{ d.prixHt }}&lt;/td&gt;
              &lt;td&gt;{{ d.prixTtc }}&lt;/td&gt;
          &lt;/tr&gt;
      {% endfor %}
      &lt;/tbody&gt;
  &lt;/table&gt;
  
  
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>On the first page, everything works fine, but after the first page break the table header floats to the left side.</p>
  
  <p>I tried to fix thead width to resolve the issue, but that didn't works.</p>
  
  <p>I tried very solution on stack or google with no closer result </p>
  
  <p>Another question please : how could i close my tablee before evreeey page break (2)</p>
  
  <p><a href="https://i.stack.imgur.com/Ufnmh.png" rel="nofollow noreferrer">PDF SCREENSHOT</a></p>
  
  <p>Thank you so much :) </p>