Home > Net >  PDF file with 6-column (multi) layout
PDF file with 6-column (multi) layout

Time:12-08

I need to create a pdf document with QR codes. I want to fit 6 QR codes in a row with border around them. But all I am getting is this:

enter image description here

As you can see it's putting them all in one row.

This is what I tried. I get data for my QR from a database, I make a QR code using phpqrcode library and then using FPDF I print the image on a PDF.

I know this is probably not the smartest solution but I need to generate QR codes and PDF in the same PHP script. Luckily, I didn't encounter any problems regarding that, since output are all different QR codes.

while ($data = mysqli_fetch_array($query)) {
    $text = $data['Id']."_".$data['IdMesto'];

    $file = "codes/qr_".$text.".png";

    $ecc = 'H';
    $pixel_size = 20;
    $frame_size = 3;
  
    QRcode::png($text, $file, $ecc, $pixel_size, $frame_size);

    $pdf->Image($file,$pdf->GetX() 5,$pdf->GetY() 5,20,20,"png");
    $pdf->Cell(30,30,"",1,0);

    
}

CodePudding user response:

Keep track of how many QR codes you have output and when the count reaches 6 tell fPDF to start a new line.

$qrcount = 0;
while ($data = mysqli_fetch_array($query)) {

    if ($qrcount == 6) {
       $pdf->Ln();
       $qrcount = 0;
    }
    $text = $data['Id']."_".$data['IdMesto'];

    $file = "codes/qr_".$text.".png";

    $ecc = 'H';
    $pixel_size = 20;
    $frame_size = 3;
  
    QRcode::png($text, $file, $ecc, $pixel_size, $frame_size);

    $pdf->Image($file,$pdf->GetX() 5,$pdf->GetY() 5,20,20,"png");
    $pdf->Cell(30,30,"",1,0);
    $qrcount  ;
    
}

CodePudding user response:

Change the cell size.

$pdf->Cell(20,20,"",1,0)
  • Related