【发布时间】:2012-01-04 08:04:04
【问题描述】:
我下载了 FPDF 1.7 并找到了一个基于 Avery 5160 标准的脚本来自动创建用于打印的标签 PDF。它似乎工作得很好,除了我打印测试页时尺寸不匹配。当我测量为每个标签打印的容器盒时,我确认我输入的测量值与打印的不匹配。
我似乎看不到的脚本是否有问题,或者 FPDF 不够精确,无法处理?
function Avery5160($x, $y, &$pdf, $text) {
$left = 4.826; // 0.19" in mm
$top = 12.7; // 0.5" in mm
$width = 76.802; // 2.63" in mm
$height = 25.4; // 1.0" in mm
$hgap = 3.048; // 0.12" in mm
$vgap = 0.0;
$x = $left + (($width + $hgap) * $x);
$y = $top + (($height + $vgap) * $y);
$pdf->SetXY($x, $y);
$pdf->MultiCell($width, 5, $text, 1, 'C');
}
$pdf = new FPDF();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Helvetica', 'B', 10);
$pdf->SetMargins(0, 0);
$pdf->SetAutoPageBreak(false);
$x = $y = 0;
foreach($arr as $text) {
Avery5160($x, $y, $pdf, $text);
$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();
}
}
}
$pdf->Output('Labels.pdf', 'D');
【问题讨论】: