Antonin Papillon
Antonin Papillon

Reputation: 1

Always the same error : HTML2PDF

(I'm french so I try to write in english) Hello, I just have do this little code :

<html>
<page>
<?php
include "top.php";
include "open_security.php";
?>

  <form method="post" action="genPDF.php">
    <p>Texte à l'intérieur du formulaire</p>
      <button type="submit">Générer</button>
  </form>

</page>
</html>

The page genPDF is the basicaly code for a PDF generator :

<?php
ob_start();
    include( "test.php" );
    $content = ob_get_clean();
   require_once( __DIR__ . "/assets/html2pdf/html2pdf.class.php");
    try
    {
        $html2pdf = new HTML2PDF("P", "A4", "fr");
        //$html2pdf->setModeDebug();
        $html2pdf->setDefaultFont("Arial");
        $html2pdf->writeHTML($content);
        $html2pdf->Output("votre_pdf.pdf");
    }
    catch(HTML2PDF_exception $e) {
        echo $e;
        exit;
    }
?>

SO, when i click on the button, I have always the same error :

ERREUR n°4
Fichier : /var/www/html/assets/html2pdf/_class/parsingHtml.class.php
Ligne : 119

Code HTML non valide, les balises ne sont pas fermées dans le bon ordre.
Etat :
Array
(
    [0] => page
    [1] => section
    [2] => section
    [3] => section
)


HTML : ...Générer</button> </form> </page> </html> </page>...

Can you help me ? I realy don't understand why it doesn't work :/

Thanks for your help

Upvotes: 0

Views: 6711

Answers (1)

RMagauran
RMagauran

Reputation: 81

The error occurs because your tags are not closed properly. If you can look at the raw html output, you will find the third <section> tag has no closing tag </section> or, more likely, there is a child element directly below this <section> tag which is not closed, perhaps around <button></button>. Do some digging. Look at Line 119 and see if there is an open, not closed or poorly formatted html structure present, or missing. The smallest thing can mess it up. I have even had errors using <span style="font-weight:bold;"></span> segments (<b></b> still works though). If you get really frustrated, break down the content output, starting blank and adding properly closed html blocks back in until html2pdf spits out an error. Voila! You will find the problem code.

html2pdf requires properly formatted html or it gives this error.

Upvotes: 1

Related Questions