0

我想使用 php 将 Data-matrix 库生成 QR 码图像存储到 mysql 数据库中。我正在尝试使用 jpgraph 库。请提供解决方案..

<?php
require_once('jpgraph/datamatrix/datamatrix.inc.php');

$data = '1234567890';

$shape       = DMAT_AUTO;
$encoding    = ENCODING_AUTO;
$modulewidth = 3;
$quietzone   = 10;
$color1      = 'black';
$color0      = 'white';
$colorq      = 'white';
$outputfile  = '';

// Create and set parameters for the encoder
$encoder = DatamatrixFactory::Create($shape);
$encoder->SetEncoding($encoding);

// Create the image backend (default)
$backend = DatamatrixBackendFactory::Create($encoder);

// By default the module width is 2 pixel so we increase it a bit
$backend->SetModuleWidth($modulewidth);

// Set Quiet zone
$backend->SetQuietZone($quietzone);

// Set other than default colors (one, zero, quiet zone/background)
$backend->SetColor($color1, $color0, $colorq);

// Create the barcode from the given data string and write to output file
try {
    $backend->Stroke($data,$outputfile);
} catch (Exception $e) {
    $errstr = $e->GetMessage();
    echo "Datamatrix error message: $errstr\n";
}
?>
4

1 回答 1

0
    $data = '123456789';

    $pdf = new Pdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetTitle('ECOMAL ');

    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

    $pdf->SetMargins(2,2,2);
    $pdf->SetHeaderMargin(0);
    $pdf->SetFooterMargin(0);

    $pdf->SetAutoPageBreak(TRUE, 0);

    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);


    if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
        require_once(dirname(__FILE__).'/lang/eng.php');
        $pdf->setLanguageArray($l);
    }

    $pdf->SetFont('helvetica', 'B', 18);

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

        $style = array(

          'fgcolor' => array(0,0,0),
          'bgcolor' => false, 

        );
    foreach ($data as  $value) {

     $tbl = '<table border="1" cellpadding="1">
        <tr><td>
            <table cellpadding="1" cellspacing="6" nobr="true">
                    <tr><td colspan="3"><h1> Vishy Intertechnology Inc.</h1></td></tr>
                    <tr><td colspan="3"><hr></td></tr>
                    <tr><td>Customer PN</td><td colspan="2" ><b>'. $value["customer_pin"].'</b></td></tr>
                    <tr><td>Customer PO</td><td colspan="2" ><b>'. $value["customer_po"] .'</b></td></tr>
                    <tr><td>Manfacture PN</td><td colspan="2" >'. $value["manufacture_pin"] .' </td></tr>
                    <tr><td>Quantity</td><td>'.$value["quantity"].'</td><td rowspan="4" width="35%"></td></tr>
                    <tr><td>Date Code</td><td>'.$value["date_of_code"] .'</td></tr>
                    <tr><td>Lot No</td><td>'.$value["lot_no"] .'</td></tr>
                    <tr><td>Serial No</td><td>'. $value["serial_no"].' </td></tr>
                    <tr><td>MSL</td><td>'.$value["msl"].'</td><td><br></td></tr>
            </table>
        </td></tr>
    </table><br><br>
    ';
        $pdf->AddPage('L','A6');
        //$pdf->SetY(50);

        $pdf->writeHTML($tbl, true, false, false, false, '');
        $pdf->write2DBarcode($value['code_string'], 'DATAMATRIX', 105, 48, 35, 35, $style, 'N');
    }
    //ob_clean();
    //Close and output PDF document
    //$rand = rand();
    $pdf->Output($_SERVER['DOCUMENT_ROOT']."/alcon/assets/ecomal.pdf", 'F');
    $pdf->Output("ecomal.pdf", 'I');
于 2019-09-09T13:31:12.847 回答