address labels using php | mysql | fpdf

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • madeo

    address labels using php | mysql | fpdf

    hi,
    i'm looking for some script which would export address labels from a
    mysql db to pdf ...

    There's an exapmle, but i'm not able to convert it for using with
    mysql ... can anybody help?

    THX a lot

    Martin :)


    =============== =============== ============
    Author: Steve Dillon (208.241.182.---)
    Date: 02-20-02 19:35

    Hi,
    I made a routine to print address labels I thought I would share. Its
    for a very common 2 5/8" wide x 1" tall address label found in the
    States. To use you need to set the page size to 8.5" x 11" and have
    the user UNCHECK "Fit to Page" when printing.

    <?php
    function odbc_fetch_arra y($res) {
    $row = array();
    $result = array();
    if ($result = odbc_fetch_row( $res)) {
    $nf = odbc_num_fields ($res)+1;
    for($count=1; $count < $nf; $count++) {
    $field_name = odbc_field_name ($res, $count);
    $field_value = odbc_result($re s, $count);
    $row[$field_name] = $field_value;
    }
    return $row;
    }
    }
    // Prints to an Avery 5160 label sheet which is a label
    // 2 5/8" wide by 1" tall, they are 3 accross on a page
    // and 10 rows per page. (30 per page). The upper left
    // corner is label(0,0) The X co-ord goes horizontally
    // accross the page and Y goes vertically down the page
    // Left/Right page margins are 4.2 MM (1/6 inch)
    // Top/Botton page margines are 12.7 MM (.5 inch)
    // Horizontal gap between labels is 4.2 MM (1/6 inch)
    // There is no vertial gap between labels
    // Labels are 66.6 MM (2 5/8") Wide
    // Labels are 25.4 MM (1" ) Tall
    function Avery5160($x, // X co-ord of label (0-2)
    $y, // Y co-ord of label (0-9)
    &$pdf,
    $Data) // String w/ line breaks to print
    {
    $LeftMargin = 4.2;
    $TopMargin = 12.7;
    $LabelWidth = 66.6;
    $LabelHeight = 25.45;
    // Create Co-Ords of Upper left of the Label
    $AbsX = $LeftMargin + (($LabelWidth + 4.22) * $x);
    $AbsY = $TopMargin + ($LabelHeight * $y);

    // Fudge the Start 3mm inside the label to avoid alignment errors
    $pdf->SetXY($AbsX+3, $AbsY+3);
    $pdf->MultiCell($Lab elWidth-8,4.5,$Data);

    return;
    }

    function PrintAddressLab els($SelectStmt )
    {
    global $cnx; // database conneciton in odbcinc.php

    $pdf=new FPDF();
    $pdf->Open();
    $pdf->AddPage();
    $pdf->SetFont('Arial ','B',10);
    $pdf->SetMargins(0,0 );
    $pdf->SetAutoPageBre ak(false);

    $cur = odbc_Exec($cnx, $SelectStmt);

    if (!$cur) {
    echo "Database Error";
    return;
    }

    $x = 0;
    $y = 0;
    while (TRUE) {
    if ($row = odbc_fetch_arra y($cur) ) {
    $LabelText = sprintf("%s\n%s \n%s, %s, %s",
    $row['MailName'],
    $row['Address'],
    $row['City'],$row['State'],$row['Zip']);
    Avery5160($x,$y ,$pdf,$LabelTex t);

    $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();
    }
    }
    } else {
    // Error quit printing
    break;
    }

    }
    $pdf->Output();
    }

    ?>
Working...