I picked up the below code from some website and it is absolutely good working code except that the wrap text feature is not available. The value of field1 below do not go to a new line if the value is long instead it overlaps to the next column. Therefore, i would like to request if anybody could give me a piece of code to solve this issue.
Code:
<?php
require('fpdf.php');
class PDF extends FPDF
{
//Page header
function Header()
{
//Logo
//$this->Image('../images/bg.png',10,8,33);
}
//Page footer
function Footer()
{
$date = date("F j, Y");
//Position at 1.5 cm from bottom
$this->SetY(-15);
//Arial italic 8
$this->SetFont('Arial','I',8);
//Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
$this->Cell(0,1,'Date '.Date("F j, Y").'/{nb}',100,0,'L');
}
}
$pdf = new PDF();
$pdf->open();
$pdf->AddPage();
$pdf->AliasNbPages(); // necessary for x of y page numbers to appear in document
$pdf->SetAutoPageBreak(false);
// document properties
$pdf->SetAuthor('INSERT AUTHOR');
$pdf->SetTitle('INSERT DOC TITLE');
$pdf->SetFont('Arial','B',10);
$pdf->Cell(40,10,'TITLE FOR REPORT');
// Add date report ran
//$pdf->SetFont('Arial','B',10);
$date = date("F j, Y");
//$pdf->Cell(40,10,'Report date: '.$date);
$pdf->SetDrawColor(0, 0, 0); //black
//table header
$pdf->SetFillColor(170, 170, 170); //gray
$pdf->setFont("Arial","B","9");
$pdf->setXY(10, 40);
$pdf->Cell(8, 10, "Sl #", 1, 0, "C", 1);
$pdf->Cell(103, 10, "Col Title1", 1, 0, "L", 1);
$pdf->Cell(15, 10, "Col Title2", 1, 0, "C", 1);
$pdf->Cell(30, 10, "Col Title3", 1, 0, "L", 1);
$pdf->Cell(20, 10, "Col Title4", 1, 0, "L", 1);
$pdf->Cell(20, 10, "Col Title5", 1, 0, "L", 1);
$y = 50;
$x = 10;
$pdf->setXY($x, $y);
$pdf->setFont("Arial","","9");
$id = $_GET['id'];
include("config.php"); // configure to point to your connection script.
global $database;
$query_result = "SELECT * FROM table WHERE id=$id and field6=0 and field7<'".$date."' order by field2 asc";
$result = $database->query($query_result);
$num = mysql_num_rows($result);
for($i=0; $i<$num; $i++)
{
$pdf->Cell(8, 8, $i+1,1, 0, "C", 0);
$pdf->Cell(103, 8, mysql_escape_string(mysql_result($result,$i,"field1")), 1); // CHANGE THESE TO REPRESENT YOUR FIELDS
$pdf->Cell(15, 8, mysql_result($result,$i,"field2"), 1, 0, "C", 0);
$pdf->Cell(30, 8, mysql_result($result,$i,"field3"), 1);
$pdf->Cell(20, 8, $database->mysql_to_ddmmyyyy(mysql_result($result,$i,"field4")), 1, 0, "C", 0);
$pdf->Cell(20, 8, $database->mysql_to_ddmmyyyy(mysql_result($result,$i,"field5")), 1, 0, "C", 0);
$y += 8;
if ($y > 260) // When you need a page break
{
$pdf->AddPage();
$y = 10;
}
$pdf->setXY($x, $y);
}
$pdf->Output();
?>
Comment