Generating pdf using php and mysql

Posted: December 20, 2012 in PHP

<?php
include “connect.php”;
require(‘fpdf.php’);

$pdf=new FPDF();
$pdf->AddPage(); //Create new PDF page

$pdf->SetFont(‘Arial’,’B’,10); //Set the base font & size

//Cell function gets two parameters:Width & Height of the Cell
$pdf->Cell(50,3,”Cool PHP to PDF Tutorial by WebSpeaks.in”);
$pdf->Ln();//Creates a new line, blank here
$pdf->Ln();

$pdf->SetFont(‘Arial’,’B’,6);
$pdf->Cell(10,5,”Sr.no.”);
$pdf->Cell(350,5,”Message”);
$pdf->Ln();
$pdf->Cell(450,3,”————————————————————————–“);

// Get data records from table.
$result=mysql_query(“select * from records order by msg_id”);
while($row=mysql_fetch_array($result))
{
$pdf->Cell(10,5,”{$row[‘msg_id’]}”);
$pdf->MultiCell(350,5,”{$row[‘message’]}”);//Necessary for generating a new line.
}
$pdf->Output();//Finally shows the output.

?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s