FPDF Layout problems

Posted on 2005-04-13
Last Modified: 2008-03-10
Hi all,

I have the following code which creates a pdf with the fpdf class found at 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

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

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

Any help is much appreciated

Question by:act1ve
    LVL 8

    Accepted 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.

    Author Comment

    thanks that worked, got my text onto the next line, think im getting the hang of this, cheers!

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now