用FPDF打印艾利5160标签[英] Printing Avery 5160 labels with FPDF

本文是小编为大家收集整理的关于用FPDF打印艾利5160标签的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我下载了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');

推荐答案

我最近使用FPDF制作一些自定义标签供工作.为了让他们与我使用的标签对齐,在打印之前,我必须在打印对话框中禁用页面缩放.不知道它是否会解决您的问题,但值得一试.

其他推荐答案

这是我解决缩放问题所需的内容

更改 $ pdf-> addpage(); 至 $ pdf-> addpage('p','letter');

将其强加给我们的字母而不是A4

标签的尺寸不正确:

$left = 4.7625; // 0.1875" in mm
$top = 12.7; // 0.5" in mm
$width = 66.675; // 2.625" in mm
$height = 25.4; // 1.0" in mm
$hgap = 3.175; // 0.125" in mm
$vgap = 0.0;

还注意浏览器的打印文档有时会缩小使用PDF查看器,并将其设置为扩展到实际尺寸而不是比例,以适合打印机对话框.

本文地址:https://www.itbaoku.cn/post/2090894.html

问题描述

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.

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');

推荐答案

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.

其他推荐答案

this is what I needed to fix the scaling issues

Change $pdf->AddPage(); to $pdf->AddPage('P','Letter');

to force it to US Letter instead of A4

The dimensions for the labels are incorrect:

$left = 4.7625; // 0.1875" in mm
$top = 12.7; // 0.5" in mm
$width = 66.675; // 2.625" in mm
$height = 25.4; // 1.0" in mm
$hgap = 3.175; // 0.125" in mm
$vgap = 0.0;

also note printing from the browser the document will sometimes scale down use a PDF viewer and have it set to scale to actual size instead of scale to fit in the printer dialog.