使用FPDF打印Avery 5160标签 [英] Printing Avery 5160 labels with FPDF
问题描述
我下载了FPDF 1.7,并找到了一个基于Avery 5160标准的脚本,可以自动创建打印标签的PDF.看起来工作得很好,除了在打印测试页时尺寸不匹配.当我测量为每个标签打印的容器盒时,我验证了输入的尺寸与打印的尺寸不匹配.
I downloaded FPDF 1.7 and found a script based on the Avery 5160 standards to automatically create a PDF of labels for printing. It seems to work quite well, except the dimensions didn't match when I printed a test page. When I measured the container box printed for each label, I validated the measurements I entered don't match what was printed.
我似乎看不见的脚本有什么问题吗?或者FPDF不够精确以至于不能解决这个问题?
Is there something wrong with the script that I can't seem to see, or is FPDF not precise enough to handle this?
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');
推荐答案
我最近使用FPDF为工作创建了一些自定义标签.为了使它们与我使用的标签对齐,必须在打印之前在打印"对话框中禁用页面缩放.不知道它是否可以解决您的问题,但是值得一试.
I was using FPDF to make some custom labels for work recently. To get them to line up with the labels I was using, I had to disable Page Scaling in the Print dialog before printing. Don't know if it will solve your problem, but it's worth a shot.
这篇关于使用FPDF打印Avery 5160标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!