สอบถามวิธีจัดตำแหน่งตัวหนังสือตามตำแหน่งภาพเสมอ FPDF

สำหรับผู้ที่ เริ่มต้น Programming - PHP มีอะไร แนะนำ หรือข้อสงสัยต้องบอร์ด นี้ คนที่มีความรู้ แบ่งปันคนอื่นบ้างนะ ปัญหาการเขียนโปรแกรม แบบ OOP Session Cookies php network

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
Tookta
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 641
ลงทะเบียนเมื่อ: 12/12/2022 9:12 am

สอบถามวิธีจัดตำแหน่งตัวหนังสือตามตำแหน่งภาพเสมอ FPDF

โพสต์ที่ยังไม่ได้อ่าน โดย Tookta »

โค้ดที่ใช้งานตอนนี้

โค้ด: เลือกทั้งหมด

$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');
การแสดงผล
Programming - PHP-1.png
Programming - PHP-1.png (18.75 KiB) Viewed 592 times
ต้องการให้ตัวหนังสืออยู่ตรงหลาง และอยู่ใหต้บาร์โค้ดเสมอ เพราะจำนวนแถวและคอลัมน์ หรือขนาดบาร์โค้ด ขึ้นอยู่กับค่าที่จะส่งมาจากอีกหน้านึง
อยากให้เป็นตำแหน่งตัวหนังสือที่ขึ้นอยู่กับตำแหน่งบาร์โค้ดเสมอค่ะ
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41232
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: สอบถามวิธีจัดตำแหน่งตัวหนังสือตามตำแหน่งภาพเสมอ FPDF

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

คำนวณพิกัด xy เพื่อระบุจุดเริ่มต้นของข้อความ อ้างอิงจัขนาดของบาร์โค้ดที่สร้าง
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ภาพประจำตัวสมาชิก
Tookta
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 641
ลงทะเบียนเมื่อ: 12/12/2022 9:12 am

Re: สอบถามวิธีจัดตำแหน่งตัวหนังสือตามตำแหน่งภาพเสมอ FPDF

โพสต์ที่ยังไม่ได้อ่าน โดย Tookta »

mindphp เขียน: 25/02/2023 7:08 am คำนวณพิกัด xy เพื่อระบุจุดเริ่มต้นของข้อความ อ้างอิงจัขนาดของบาร์โค้ดที่สร้าง
สามารถทำได้แล้วค่ะ

โค้ด: เลือกทั้งหมด

 $pdf->Image($generate_pdf, $x, $y, $cell_width, 0, 'png');

  $pdf->SetFont('THSarabunNew', 'B', 14);

  $pdf->SetXY($x + ($cell_width / 12 -3), $y + ($cell_height / 2 -3 ) - 13); 
  $pdf->Cell($cell_width, 8, iconv('UTF-8', 'TIS-620', $generate_pdf_pdnumber), 0, 0, 'C');


  $pdf->SetXY($x + ($cell_width / 12 -3), $y + ($cell_height / 2 -1 ) - 8); 
  $pdf->Cell($cell_width, 8, iconv('UTF-8', 'TIS-620',  $generate_pdf_pdname), 0, 0, 'C');

  $pdf->SetXY($x + ($cell_width / 12 -3), $y + ($cell_height / 2 +2) -7); 
  $pdf->Cell($cell_width, 8, iconv('UTF-8', 'TIS-620',  $generate_pdf_pdprice.'  '.$currency), 0, 0, 'C');
Programming - PHP-1.png
Programming - PHP-1.png (10.72 KiB) Viewed 488 times
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 118