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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

762 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