?
Solved

fpdf layout

Posted on 2005-03-22
4
Medium Priority
?
668 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
  • 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

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