Learn how to a build a cloud-first strategyRegister Now

x
  • 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:

 <?php

include 'db.php';
require('fpdf.php');

$userid=$_GET["userid"];
$orderid=$_GET["orderid"];

$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->AddPage();

$pdf->Image('logo.jpg',10,10);
$pdf->SetFont('Helvetica','U',16);
$pdf->Cell(500,80,'Your Invoice');
$pdf->Ln(10);


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


$pdf->Ln(145);
$pdf->SetTextColor(255, 165, 0);
$pdf->Cell(70,10,'text');
$pdf->Cell(80,10,'text');
$pdf->Cell(80,10,'text');
$pdf->Output("invoice.pdf",false);
redirect("email.php?orderid=$orderid&userid=$userid");

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


function redirect($url) {
    echo '<script language="JavaScript">
    document.location.href="' . $url . '"
    </script>';    
    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:

logo

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



0
act1ve
Asked:
act1ve
1 Solution
 
_Marcel_Commented:
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.
0
 
act1veAuthor Commented:
thanks that worked, got my text onto the next line, think im getting the hang of this, cheers!
0

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