Reputation: 11882
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');
Upvotes: 4
Views: 9437
Reputation: 11
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.
Upvotes: 1
Reputation: 1194
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.
Upvotes: 3