Jump to content

Printing to 4x6 labels


ultraloveninja

Recommended Posts

Hi there!

 

I found this code to parse a MySQL query to PDF, but it's for small address labels and I was wondering how to make it for 4x6 labels?

<?php
define('FPDF_FONTPATH','/home/directory/public_html/sub/font/');
require_once('fpdf.php');
//Connect to your database
mysql_connect("localhost", "db_user","db_pw") or
    die ("Could not connect to database");
mysql_select_db("database_name") or
    die ("Could not select database");

$query  = "SELECT employee_name, street_address, City, state, zip_code FROM employees ORDER BY `employee_name` ";
$result = mysql_query($query) or die('Error, query failed');
$num_rows = mysql_num_rows($result);

function PrintAddressLabels($result){ 


  $pdf=new FPDF(); 

  $pdf->Open();
  $pdf->AddPage(); 
  $pdf->SetFont('Arial','B',14);
  $pdf->SetMargins(0,0); 
  $pdf->SetAutoPageBreak(false); 
  $x = 0;
  $y = 0;
  $i=0;

  while (TRUE) {

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

      //positions set above 
      $LabelText = sprintf("%s\n%s %s\n%s, %s, %s", 
      $row['employee_name'],
      $row['street_address'],
      $row['City'],
      $row['state'],
      $row['zip_code']);


      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('mailing_labels.pdf','D');
}
?>

 

Does anyone know where I can find some good resources/tutorials that covers how to use the PDF stuff with PHP or know how I can change this up to match for 4x6 at all?

 

Any help or info is greatly appreciated!

 

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.