The PDF for Avery labels 5160 is created beautifully, but every other page is blank. I have only 7 labels, which are the odd-numbered pages, but I end up with 13 because all the even-numbered pages are blank. I've double-checked the measurements for the margins and the space between the next label.
// SESSION Stuff here
} else {
require_once('inc/pdf_label.php'); // extends FPDF - http://www.fpdf.org/en/script/script29.php
$pdf = new PDF_Label('5160');
$pdf->AddPage();
$pdf->SetFont('Helvetica', '', 10);
$pdf->SetMargins(0, 0);
$pdf->Footer(false);
$pdf->Header(false);
$pdf->SetAutoPageBreak(false); // setting true creates same result of blank pages
// get DB table info to print labels
$sql = "SELECT * FROM `my_table` WHERE `delivery_format`='Postal' && `membership_expires` >= '" . $ninety_days . "' ORDER BY `name_merge` ASC";
if(!$result = $xxxx_db->query($sql)) {
die("There was an error running the query [" . $xxxx_db->error . "]");
}
$x = 0;
$y = 0;
while($row = $result->fetch_assoc()) {
$dates = "Expires:" . date('n/j/y', strtotime($row['membership_expires'])) . " Joined:" . date('n/j/y', strtotime($row['signup_date']));
$text = sprintf("%s\n%s\n%s\n%s %s %s",
$dates,
$row['name_merge'],
$row['street'],
$row['city'],
$row['state'],
$row['zip']);
$pdf->Add_Label($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('my_labels', 'I');
}
The handling of
$xand$yis obsolete as this is handled internally by thePDF_Labelclass.Same for the
AddPage()call which is the main issue for your problem. Just remove this and it should work.The souce code of the class can be found here. You can find the whole handling of rows and cols and also the
AddPage()call in theAdd_Label()method.