fpdf layout

Posted on 2005-03-22
Medium Priority
Last Modified: 2013-12-12

Im struggling with the layout formate used for the fpdf class that im using wth php to generate receipts on the fly. basically the pdf content is going all over the place when i call the variables to the printed out and i cant figure out how exactly the layout manager works no matter how much i study the examples on fpdf.org.

an example of my current output is:


the code im using to generate this so far is:

include ('db.php');
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

if(isset($_POST["Submit"])) {

 $sql = mysql_query("Select * From tracking Where C_Pass = '" . $_POST["trackingnum"] . "'") or die ("Sql error : " . mysql_error());

 if( mysql_num_rows($sql) > 0 ) {

 $row = mysql_fetch_array($sql);
 $C_Pass = $row["C_Pass"];
 $C_Fname = $row["C_Fname"];
 $C_Surname = $row["C_Surname"];
 $C_Street = $row["C_Street"];
 $C_Street1 = $row["C_Street1"];
 $C_Town = $row["C_Town"];
 $C_City = $row["C_City"];
 $C_Country = $row["C_Country"];
 $p_id = $row["p_id"];
 $invoicedate = date("l dS of F Y ");

 $pdf=new FPDF();


 $pdf->Cell(70,10,'Bill to:');
 $pdf->Cell(100,10, $C_Fname . " " . $C_Surname);
 $pdf->Cell(10,10,'Reference No:');
 $pdf->Cell(70,10, $C_Street);
 $pdf->Cell(80,10,'Invoice Date: ' . $invoicedate);
 $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,'Goods Ordered:');
 $pdf->Cell(70,10,'Invoice Total:');
 $pdf->SetTextColor(254, 0, 0);


 else {
   echo "You Must Enter a tracking code to view details. Please go back and enter a valid code.";



is there anyone that has used the class before that could help with fixing this layout problem?


Question by:clonmelog
  • 2
  • 2
LVL 49

Accepted Solution

Roonaan earned 2000 total points
ID: 13602534
Have you tried using just $pdf->Ln(); without param?

What I used for my program was the script below. The PDF class was an extionsion of FPDF class, but with some predefined headers on each page. This should not affect the general page content however:

    $pdf=new PDF();
    $pdf->setFont('Times', 'B', 14);
    $text = array();
    $text[] = "A\tB\tC";
    $text[] = "A\tB\tC";
    $text[] = "A\tB\tC";
    $text[] = "A\tB\tC";
    $text[] = "A\tB\tC";
    $text[] = "A\tB\tC";
    foreach($text as $row)
      $n = explode("\t",$row);
      $pdf->Cell(30,9, isset($n[0]) ? $n[0] : '');
      $pdf->Cell(30,9, isset($n[1]) ? $n[1] : '');
    $pdf->setFont('Arial', '', 12);
    $pdf->Write(5, "Textline 1"); $pdf->Ln();
    $pdf->Write(5, "Textline 2"); $pdf->Ln();
    $pdf->Write(5, "Textline 3"); $pdf->Ln();
    $pdf->Write(5, "Textline 4"); $pdf->Ln();
    $pdf->Write(5, "Textline 5"); $pdf->Ln();


Hope this helps


Author Comment

ID: 13626437
yeah thats a better layout system than what i was using already. one thing though is how exactly do you control the alignment of text and the likes??
LVL 49

Expert Comment

ID: 13626453
Alignment as in Left-aligned, centered/justified, right aligned? I have never tried that actually. But I suppose it should be possible.


Author Comment

ID: 13626498
yeah just like in say HTML layout.

The points are yours but if you come up with anything please let me know ;)

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

621 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