Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3527
  • Last Modified:

FPDF Layout problems

Hi all,

I have the following code which creates a pdf with the fpdf class found at fpdf.org. All works well but i am having a few problems with the layout.

Here is my code:


include 'db.php';


$sql = mysql_query("Select * From users Where userid = '$userid'") or die ("Sql error : " . mysql_error());

if( mysql_num_rows($sql) > 0 ) {

$sql1= mysql_query("SELECT * FROM tblOrder WHERE orderid='$orderid'") or die ("Sql error : " . mysql_error());
$row1= mysql_fetch_array($sql1);
$row = mysql_fetch_array($sql);

$Start = $row1["order_date"];
$Finish = $row1["renew_date"];
$Price = $row1["price"];
$P_method = $row1["p_method"];
$C_Fname = $row["C_Fname"];
$C_Fname = $row["C_Domain"];
$C_Surname = $row["C_Surname"];
$C_Street1 = $row["C_Street1"];
$C_Street2 = $row["C_Street2"];
$C_Town = $row["C_Town"];
$C_City = $row["C_City"];
$C_Country = $row["C_Country"];
$p_id = $row["p_id"];

$pdf=new FPDF();

$pdf->Cell(500,80,'Your Invoice');

$pdf->Cell(70,10,'Bill to:');
$pdf->Cell(70,10, $C_Fname . " " . $C_Surname);
$pdf->Cell(70,10,'Billing Address:');
$pdf->Cell(70,10, $C_Street);
$pdf->Cell(70,10, $C_Street1);
$pdf->Cell(70,10, $C_Town);
$pdf->Cell(70,10, $C_City);
$pdf->Cell(70,10, $C_Country);
$pdf->Cell(70,10,'Hosting Ordered:');
$pdf->Cell(70,10,'Plan Ordered:' . $p_id);
$pdf->Cell(70,10,'Subdomain:' . $C_Domain);
$pdf->Cell(70,10,'Start Date:' . $Start);
$pdf->Cell(70,10,'Rewenal Date:' . $Finish);
$pdf->Cell(70,10,'Payment Method:' . $P_method);
$pdf->Cell(70,10,'Total Price:' . $Price);

$pdf->SetTextColor(255, 165, 0);

else {
  echo "No result for the query, PDF not generated";

function redirect($url) {
    echo '<script language="JavaScript">
    document.location.href="' . $url . '"
    echo "If you do not get redirected <a href=\"" . $url . "\">click here</a>.";

For some reason the Invoice wording appears in the same cell block as my logo? Also i would like to include colours similar to the tutorial found at http://www.fpdf.org/en/tutorial/tuto3.htm

I particulary like the Chapter 1: A Runaway Reef layout part.

However i'm unable to understand the way they are using their code to implement it at all.

Does anyone know how i could fix up my pdf so i have:


Your Invoice -> like the the Chapter 1 example at fpdf.org

The rest of my output seems to be ok, just the above im having trouble with.

Any help is much appreciated

1 Solution
It's been a while ago when I last used this class, but as far as I remember, pictures were not actually being put into a cell. If you want to position the text underneath the picture, you need first to position to that point. So try putting a $pdf->Ln(20); after you insert the picture.
act1veAuthor Commented:
thanks that worked, got my text onto the next line, think im getting the hang of this, cheers!

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now