如何使用 TCPDF 和 PHP 在总页宽 108mm x 19mm 的 4 个单元格中对齐条码,边距为 4mm 左/右和 2mm 顶部/底部?

问题描述 投票:0回答:0

我目前正在做一个项目,我需要生成一个 PDF,其中包含 4 个条形码,在总页面宽度为 108mm x 19mm 的 4 个单元格中对齐。每个单元格的宽度应为 25mm x 15mm,左/右边距为 4mm,顶部/底部边距为 2mm。

我正在使用 TCPDF 和 PHP 生成 PDF,我尝试了一些解决方案,但似乎没有一个能按预期工作。我附上了我想要实现的目标的图像,以及我当前的 TCPDF/PHP 代码以供参考。

 <?php


// Include the main TCPDF library (search for installation path).
require_once('tcpdf/tcpdf.php');

// create new PDF document
$width=108;
$height=19.05;
$pageLayout = array($height,$width );
$pdf = new TCPDF('L', 'mm', array(108,195), true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 027');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

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



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

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

$pdf->SetMargins(0.2, 0.3, 0.4, true); // put space of 10 on top 

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

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



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

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

// define barcode style
$style = array(
    'position' => '',
    'align' => 'L',
    
            'hpadding' => 'auto',
            'vpadding' => 'auto',
    'stretch' => false,
    'fitwidth' => true,
    'cellfitalign' => '',
    'fgcolor' => array(0,0,0),
    'bgcolor' => false, //array(255,255,255),
    
);
$pdf->setCellMargins(1, 1, 1, 1);
// PRINT VARIOUS 1D BARCODES
$x=5;
// CODE 128 AUTO
for($i=1;$i<=4;$i++){
$pdf->MultiCell(25, 15, '', 1, 'C', 0, 0, '', '', true);
$pdf->write1DBarcode('1120', 'C128', $x, '', 20, 10, 0.4, $style, 'LTR');

 $x=$x+25;
}
//Close and output PDF document
$pdf->Output('example_027.pdf', 'I');

//============================================================+
// END OF FILE
//============================================================+

Want this as pdf

php barcode tcpdf
© www.soinside.com 2019 - 2024. All rights reserved.