user5619474
user5619474

Reputation: 33

FPDF creating shipping label

I am trying to use FPDF to create a pdf of one of my database tables. Basically, I want to click a print button and have the information auto populate on a PDF. What I have tried on my own has failed, I can't seem to wrap my head around this.

How the printing label should look

Example of the table being used

<?php
require("fpdf/fpdf.php");

mysql_connect("localhost", "[username]","[password]") or die ("Could not connect     to database");
mysql_select_db("[db_name]") or die ("Could not select database");

$query  = "SELECT ID_Shipping, ID_Order, Shipping_Company FROM     SeniorDB_Shipping ORDER BY `ID_Shipping` ";
$result = mysql_query($query) or die('Error, query failed');
$num_rows = mysql_num_rows($result);


class PDF extends FPDF
{
// Page header
    function Header()
    {
        // Logo
        $this->Image('minilogo.png',10,6,50);
        // Arial bold 15
        $this->SetFont('Arial','B',15);
        // Move to the right
        $this->Cell(80);
        // Title
        $this->Cell(55,10,'Shipping Information',1,0,'C');
        // Line break
        $this->Ln(20);
    }
}

    // Instanciation of inherited class
    $pdf = new PDF();
    $pdf->AliasNbPages();
    $pdf->AddPage();
    $pdf->SetFont('Times','',12);

    //$pdf->Cell(40,10,'Hello World!');

     while (TRUE) {

    if ($row=$result[$i]) {

      //positions set above 
      $LabelText = sprintf("%s\n%s %s\n%s, %s, %s", 
      $row['ID_Shipping'],
      $row['ID_Order'],
      $row['Shipping_Company']);


       Avery5160($x,$y,&$pdf,$LabelText);

      $y++; // next row 
      if ($y == 10 ) { // end of page wrap to next column 
        $x++; 
        $y = 0; 
        if ($x == 3 ) { // end of page 
          $x = 0; 
          $y = 0; 
          $pdf->AddPage(); 
        }
      }
      $i++; //counter through result
    } else {
      // Error quit printing 
      break; 
    }

  }
    $pdf->Output();
?>

Upvotes: 1

Views: 2412

Answers (1)

Hilarius L. Doren
Hilarius L. Doren

Reputation: 757

make sure you use the $pdf->Output(); with the option for example $pdf->Output('I');

for more information about the function/class you can see here http://www.tcpdf.org/doc/code/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1

Upvotes: 1

Related Questions