Printing Avery 5160 labels with FPDF

余生长醉 提交于 2019-12-04 13:31:20

问题


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

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/8235262/printing-avery-5160-labels-with-fpdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!