(Guide For Windows. Not Mac or Linux)
(Image Source)
There's more than one way to convert HTML to a PDF in PHP. You can use Dompdf or Mpdf; however, there is a difference in how these two libraries are doing it.
Note: Not all solutions will be in this article.
To use both these libraries, you will need Composer.
I also show the code in the article discussing why the PDF sometimes won't open when using Dompdf.
Hello World'; // instantiate and use the dompdf class $dompdf = new Dompdf(); $dompdf->loadHtml($content); // (Optional) Setup the paper size and orientation $dompdf->setPaper('A4', 'landscape'); // Render the HTML as PDF $dompdf->render(); ob_end_clean(); // Output the generated PDF to Browser $dompdf->stream(); ?>
With this code, the PDF is downloaded.
WriteHTML('Hello world! Hi
'); $mpdf->Output(); ?>
With this code, the PDF is opened in the browser when you navigate to your file (Example: localhost/test1.php)
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3