title: how to add dynamically generated qrcodes to pdf for labels using fpdf and pdf_label
body: <p>I have some records stored on a database. I would like to print them onto some Avery labels. I can use FPDF to create a pdf document. I can use PDF_Label which extends FPDF to easily position the information to align with Avery labels. So far so good. </p>
  
  <p>In addition to outputting text, I would like to represent some of the data in a qr code. I can create the qr codes, storing them temporarily on disk as .png files. I can insert the qr_codes as images into a .pdf document. So far so good.</p>
  
  <p>But here is the problem: PDF_label creates 'cells' which align with Avery labels and specifically handles text, not images. How can I 'easily' insert each qr code into each label? </p>
  
  <p>I have looked online for two days but there seems very little guidance on this - other than one piece of advice that sepcicially warns NOT to insert images into FPDF Cells. </p>
  
  <p>One option perhaps would be to use TCPDF but I would appreciate some recommendations on what extension if any would be useful.</p>
  
  <p>For the record, my code so far is:</p>
  
  <pre><code>&lt;?php
      require_once( 'vendor/fpdf181/fpdf.php' );
      require_once( 'vendor/fpdf_label/PDF_Label.php');
      require_once( 'vendor/phpqrcode/qrlib.php' );
  
     // fetch data from database
     /* … works fine and creates an array of locations … */
  
     foreach( $locations as $location )
     {
          $title          = "Location " . $location['id'];
          $name           = $location['name'];
          $footer         = "https://www.example.com/something/";
          $barcode_text   = "https://www.example.com/something/?t=1&amp;u=1&amp;l=" . $location['id'];
  
          // create a temporary file to hold the barcode.png
          $filePath       = './qr_codes/temp_'. $location['id'] . '.png';
  
          $qr_code        = new QRcode();
          QRcode::png( $barcode_text, $filePath );
  
  
  
          $text  = "";
          $text .= sprintf( $title . "\n" . $name . "\n");
          $text .= $pdf-&gt;Image( $filePath, $pdf-&gt;GetX(), $pdf-&gt;GetY(), 20 );
          $text .= sprintf( "\n" . $footer );
  
  
          //$pdf-&gt;Add_Label($text);
          $pdf-&gt;Add_Label($text);
  }
  </code></pre>
  
  <p>From 7 records, this generates just 3 qrcodes on the pdf. Possibly several images overlay one another. The qr_codes are vertically aligned for the top of each row of labels but not correctly positioned horizontally. Presumably this is because that is the position given by GetX and GetY at the time those methods are called.</p>
  
  <p>Any help much appreciated ...</p>