Abhishek
Abhishek

Reputation: 603

Create HTML to PDF file using html2pdf library

I am using html2pdf library to generate pdf file in wordpress. Using this I am able to create pdf file but when i try to open this file it shows the error : "format error : not a pdf or currupted". my code is:

 $content = "<page><h1>Exemple d'utilisation</h1><br>Ceci est un <b>exemple d'utilisation</b>de <a href='http://html2pdf.fr/'>HTML2PDF</a>.<br></page>";
    include('html2pdf/html2pdf.class.php');
    try
    {
        ob_end_flush();
        ob_get_clean();
        ob_end_clean();

        $html2pdf = new HTML2PDF('L', 'Legal', 'fr');
        $html2pdf->pdf->SetDisplayMode('fullpage');
        $html2pdf->setDefaultFont('Arial');
        $html2pdf->writeHTML($content);
        $html2pdf->Output("report.pdf",'D');
    }
    catch(HTML2PDF_exception $e) {
        echo 'exceptional error='.$e;
        exit;
    }

Please suggest where I am going to wrong.

Thanks in advance.

Upvotes: 1

Views: 1061

Answers (1)

Daria Pydorenko
Daria Pydorenko

Reputation: 1802

Maybe, pdf isn't closed correctly, try to add exit; at the end of try-block:

try
{
   ...
   exit;
}

And you are sure that Output must be start with capital letter?

Upvotes: 2

Related Questions