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


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


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


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


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.



  • pinij July 06, 2018


    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


    • Webpreparations Team July 08, 2018

      Please share your code.


Leave a comment:

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