Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Wie kann ich TCPDF verwenden, um 2x6-Bögen mit Etiketten zu erstellen, die 2D-Barcodes enthalten, OHNE Spalten ODER Klassen von Drittanbietern zu verwenden?

Schauen Sie sich meine Lösung an - sie kann 24 Etiketten drucken - 3 * 8 in A4. Nehmen Sie einfach eine einfache Änderung in Breite, Höhe und $menge vor, und Sie können 2 * 6 erhalten.

<?php

include("dbconfig.php");

require_once('../tcpdf/tcpdf.php');
// include 1D barcode class (search for installation path)
require_once('../tcpdf/tcpdf_barcodes_1d.php');

date_default_timezone_set('Asia/Kolkata');


// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, 'mm', 'A4', true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Casual Creators');
$pdf->SetTitle('Bar Code Labels');
$pdf->SetSubject('');
$pdf->SetKeywords('');

//remove header and footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->setTopMargin(13.0);
$pdf->SetRightMargin(6.0);

$pdf->setHeaderMargin(13);
$pdf->SetFooterMargin(13.0); //13mm

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 13.0);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);



// set a barcode on the page footer
//$pdf->setBarcode(date('Y-m-d H:i:s'));

// set font
$pdf->SetFont('helvetica', '', 11);

// add a page
$pdf->AddPage();

// print a message
//$txt = "";
//$pdf->MultiCell(70, 50, $txt, 0, 'J', false, 1, 125, 30, true, 0, false, true, 0, 'T', false);
//$pdf->SetY(30);

// -----------------------------------------------------------------------------

$pdf->SetFont('helvetica', '', 10);

// define barcode style
$style = array(
        'position' => '',
        'align' => 'L',
        'stretch' => false,
        'fitwidth' => false,
        'cellfitalign' => '',
        'border' => false,
        'hpadding' => 'auto',
        'vpadding' => 'auto',
        'fgcolor' => array(0,0,0),
        'bgcolor' => false, //array(255,255,255),
        'text' => true,
        'font' => 'helvetica',
        'fontsize' => 8,
        'stretchtext' => 0
);


//63.5 mm label width
//33.9mm label height
//2.5 mm gap between

// PRINT VARIOUS 1D BARCODES

// CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.


$query1 = "SELECT * FROM PRODUCTS WHERE ID = '123456' ";

$result1 = $conn->query($query1);
$qty = 24;
$item ;

if ($result1-> num_rows > 0)  {

    $row = $result1 -> fetch_assoc();

    $item = $row["id"];
}
else {
    echo 'DbFailed';
}

$counter = 1;

$i = '0' ;

for( ; $i < $qty ; $i++)
{

    $x = $pdf->GetX();
    $y = $pdf->GetY();
    $pdf->setCellMargins(0,0,2.5,0);
    // The width is set to the the same as the cell containing the name.
    // The Y position is also adjusted slightly.
    $pdf->write1DBarcode($item , 'C39', $x-2.5, $y-6.5, 63.5, 18, 0.4, $style, 'L');
    //Reset X,Y so wrapping cell wraps around the barcode's cell.
    $pdf->SetXY($x,$y);
    $pdf->Cell(63.5, 25, 'MyProduct', 0, 0, 'L', FALSE, '', 0, FALSE, 'C', 'B');
    $pdf->SetXY($x,$y);
    $pdf->Cell(63.5, 33, 'Price', 0, 0, 'L', FALSE, '', 0, FALSE, 'C', 'B');

    if($counter == 3)
    {
        $pdf->Ln(33.9);
        $counter = 1;
    }else{
        $counter++;
    }

}




// ---------------------------------------------------------
ob_end_clean();
//Close and output PDF document
$pdf->Output('barcodes.pdf', 'I');

?>