?
Solved

fpdf layout

Posted on 2005-03-22
4
Medium Priority
?
664 Views
Last Modified: 2013-12-12
Hi,

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:

http://www.substanceabuseawareness.com/invoice.pdf

the code im using to generate this so far is:

<?php
include ('db.php');
require('fpdf.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->AddPage();

 $pdf->SetFont('Helvetica','U',16);
 $pdf->Image('logo.jpg',80,10,50);
 $pdf->Ln(3);
 $pdf->SetDrawColor(0,80,180);
 $pdf->SetFillColor(230,230,0);
 $pdf->Cell(80,10,'test');
 $pdf->Ln(40);

 $pdf->SetFont('Helvetica','',12);
 $pdf->Cell(70,10,'Bill to:');
 $pdf->Ln(10);
 $pdf->Cell(100,10, $C_Fname . " " . $C_Surname);
 $pdf->Cell(10,10,'Reference No:');
 $pdf->Cell(160,10,$C_Pass);
 $pdf->Ln(10);
 $pdf->Cell(70,10, $C_Street);
 $pdf->Cell(80,10,'Invoice Date: ' . $invoicedate);
 $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,'Goods Ordered:');
 $pdf->Ln(6);
 $pdf->Cell(70,10,'Invoice Total:');
 $pdf->Ln(120);
 $pdf->SetTextColor(254, 0, 0);
 //$pdf->Cell(70,10,'www.substanceabuseawareness.com');
 $pdf->Cell(500,10,'shopping@substancebuseawareness.com','c');

 $pdf->Output("invoice.pdf",true);

 }
 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?

thanks






0
Comment
Question by:clonmelog
[X]
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
4 Comments
 
LVL 49

Accepted Solution

by:
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->SetTitle('....');
    $pdf->SetAuthor('....');
    $pdf->AddPage();
    $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";
 
    $pdf->Ln(30);
    foreach($text as $row)
    {
      $n = explode("\t",$row);
      $pdf->Cell(20,0,'');
      $pdf->Cell(30,9, isset($n[0]) ? $n[0] : '');
      $pdf->Cell(30,9, isset($n[1]) ? $n[1] : '');
      $pdf->Ln();
    }
    $pdf->Ln(10);
    $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();

    $pdf->Output('','s');

Hope this helps

-r-
0
 
LVL 2

Author Comment

by:clonmelog
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??
0
 
LVL 49

Expert Comment

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

-r-
0
 
LVL 2

Author Comment

by:clonmelog
ID: 13626498
yeah just like in say HTML layout.

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

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