0
点赞
收藏
分享

微信扫一扫

php使用tcpdf生成100面单

zhyuzh3d 2022-10-22 阅读 135
  1. 完整代码

<?php

require_once("TCPDF-master/tcpdf.php");
require_once("TCPDF-master/tcpdf_barcodes_1d.php");
require_once("fpdi/fpdi.php");

$pdf = new TCPDF('P', 'mm', array(100, 100), true, 'UTF-8', false);

//条形码样式
$style = array(
'position' => '',
'align' => 'C',
'stretch' => false,
'fitwidth' => true,
'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' => 4
);

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(2, 1, 2);

$pdf->SetAutoPageBreak(TRUE);
$pdf->AddPage();
$pdf->SetFont('helvetica', 'B', 15);

$pdf->SetFont('stsongstdlight','B', 10);
$pdf->MultiCell(48, 20, '', 1, 'C', 0, 0, '', '', true);
$pdf->MultiCell(48, 20, 'FR 1 OF 1'."\n".'箱子规格(cm):10*10*10'."\n".'箱子重量(kg):20'."\n".'商品种类', 1, 'L', 0, 0, '', '', true);
$x = $pdf->getX();
$y = $pdf->getY();
$pdf->write1DBarcode('GLDJNEW2342342342', 'C128', $x-95, $y, '45', 20, 0.4, $style, 'N');

$pdf->MultiCell(48, 15, '公司', 1, 'L', 0, 0, '', '', true);
$pdf->MultiCell(48, 15, "专属客服:深圳市", 1, 'L', 0, 1, '', '', true);
$pdf->MultiCell(96, 60, "234892389472897", 1, 'L', 0, 1, '', '', true);


$pdf->SetFont('helvetica', 'B', 12);
$pdf->Output("newpdf".rand(100,9999999).".pdf", "I");

?>

  1. 说明

$x = $pdf->getX();
$y = $pdf->getY();
$pdf->write1DBarcode('GLDJNEW2342342342', 'C128', $x-95, $y, '45', 20, 0.4, $style, 'N');

条形码使用绝对定位,并且必须是添加在要定位cell的后面,否则页面内容会错位,很不好调试。

举报

相关推荐

0 条评论