1

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.

1
  • use mpdf library its easy to use Commented Aug 4, 2017 at 11:59

1 Answer 1

2

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.