โค้ด: เลือกทั้งหมด
$col = 0; // ตัวแปรเก็บจำนวนคอลัมน์
$row = 0; // ตัวแปรเก็บจำนวนแถว
$cell_height = 60; // ความสูงของแต่ละเซลล์
$margin_left = 5; // ระยะห่างจากขอบซ้าย
$margin_top = 10; // ระยะห่างจากขอบบน
$cell_spacing = 10; // ระยะห่างระหว่างเซลล์
$cell_width = ($pdf->GetPageWidth() - 2 * $margin_left - ($generate_pdf_amount - 1) * $cell_spacing) / $generate_pdf_amount;
$cell_total_height = $cell_height + 25 + 8 + 8;
for ($i = 1; $i <= $amount; $i++) {
if ($col >= $generate_pdf_amount) { // แก้ไขจำนวนคอลัมน์
$row++;
$col = 0;
if (($row * $cell_total_height) > ($pdf->GetPageHeight() - $margin_top)) {
$pdf->AddPage();
$col = 0;
$row = 0;
$margin_top = 10;
}
}
$x = $margin_left + $col * ($cell_width + $cell_spacing);
$y = $margin_top + $row * $cell_total_height;
$pdf->Image($generate_pdf, $x, $y, $cell_width, 0, 'png');
$pdf->SetXY($x + ($cell_width / 2), $y + ($cell_height / 2) - 20);
$pdf->Cell($cell_width, 8, iconv('UTF-8', 'TIS-620', $generate_pdf_pdnumber), 0, 0, 'C');
$pdf->SetXY($x + ($cell_width / 2), $y + ($cell_height / 2) - 10);
$pdf->Cell($cell_width, 8, iconv('UTF-8', 'TIS-620', 'ชื่อสินค้า : ' . $generate_pdf_pdname), 0, 0, 'C');
$pdf->SetXY($x + ($cell_width / 2), $y + ($cell_height / 2) - 5);
$pdf->Cell($cell_width, 8, iconv('UTF-8', 'TIS-620', 'ราคาสินค้า : ' . $generate_pdf_pdprice), 0, 0, 'C');
$pdf->SetY($y + $cell_height + 5);
$col++; // เพิ่มจำนวนคอลัมน์
}
$pdf->Output('my_file.pdf', 'I');
อยากให้เป็นตำแหน่งตัวหนังสือที่ขึ้นอยู่กับตำแหน่งบาร์โค้ดเสมอค่ะ