12 Nov, 2017

How to generate pdf in PHP using MySQL and MPDF Library

12 Nov, 2017

Dear Reader, let us we know that “How to generate PDF in PHP using Mysql and MPDF Library“. So in this Tutorial, We Learn Step By Step  How to generate PDF from HTML Process.

PDF stands for  Portable Document Format. PDF is a file format that used to presents documents in a manner independent of application software, hardware and operating system.PDF files are created using Adobe Acrobat, Acrobat Capture, or similar products. To view and use the files, you need the free Acrobat Reader, which you can easily download.

First, we see Snapshots for our Export data to PDF format

how-to-generate-pdf-in-php-using-MPDF-library-step-1

Step 1:- First of all you need to create the database like ci_demo

Step 2:- Now create a table “mobiles” in a database using the below SQL code

Step 3:- Now dump some data for table “mobiles” using bellow SQL code

Step 4:- Now we need to download MPDF library here and extract this in your project root directory as we can see in below snapshot

Step 5:- Now Create mobiles.php file and paste the below code

Step 6:-  In mobiles.php we add some CSS and JS, so download assets folder here 

extract zip file and copy assets folder and paste in your project’s root directory as we can see in below snapshot

how-to-generate-pdf-in-php-using-MPDF-library-step-3

Step 7:- Now run your project, so you need to type in browser localhost/your_project_name/mobiles.php

like

http://localhost/php_demo/mobiles.php then you can see the result as in below snapshot, you can Export data in PDF format by click on Generate PDF button

how-to-generate-pdf-in-php-using-MPDF-library-step-1

Congratulations you have successfully generate PDF with MySQL data into PDF format in PHP using MPDF library, if you like this post and was helpful for you then share this post on social media and if you have any query then please contact us or comment below, Thanks.

«
»

2 Comments:

  • pinij July 06, 2018

    Error

    Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home/yourcompa1/domains/yourcompanyprofile.com/public_html/PDF/mobiles.php on line 82

    Reply

    • Webpreparations Team July 08, 2018

      Please share your code.

      Reply

Leave a comment:

Your email address will not be published. Required fields are marked *