Create PDF in PHP


In this article I will explain how to display data in a PDF file using PHP. To creating the PDF file, I will first includ the "fpdf.php" file of your pdf.php. This file you can download free for creating PDF files. Mostly for creating PDF and display the data in a PDF file so this file fpdf.php and the font requirements of your new PDF file. The font folder includes many types of fonts and this folder is put in the same directory, "www".


This is a "connection.php" for creating a connection to your table in a MySQL database:


$con = mysql_connect("localhost","root","");

if (!$con)


  die('Could not connect: ' . mysql_error());



mysql_select_db("smart", $con);


mysql_query("SELECT * From form");



This is a "pdf.php" file for creating a PDF page and in this file, I have included a connection.php file and fpdf.php file, both files are saved in the same directory. I am using this script for creating a PDF and displaying the data from your table. I have used our table and displayed some data. Such as display Id, name, mobile, email in PDF on our browser.
Mysql table.jpg
pdf=new FPDF();

//Creating new pdf page

//Set the base font & size
$pdf->Cell(100,5,"Create PDF File In PHP");
//Creating new line

// Fetch data from table

 $result=mysql_query("select * from form");










Display Pdf in PHP.jpg

Up Next
    Ebook Download
    View all
    View all