title: How do I print a barcode using barcode generator for PHP onto a pdf formatted page where I want it?
body: <p>Alright so first things first:</p>
  
  <p>I've searched over this site for 6+ hours and I keep coming up with the same results. The main answer I keep getting is: <a href="https://stackoverflow.com/questions/16022496/how-to-generate-barcode-using-php-and-display-it-as-an-image-on-the-same-page">How to Generate Barcode using PHP and Display it as an Image on the same page</a></p>
  
  <p>But this is not working for me. Even the answer on that page that was accepted ends with "After you have added all the codes, you will get this way:" which is so vague I feel like I'm supposed to already be an expert to understand it. I'm getting frustrated with this problem because I cannot seem to find any "moron directions" that can help me understand how everything works in this library for barcode generator for php.</p>
  
  <p>Here is what I have:</p>
  
  <p>I'm using fpdf to print a pdf file which works great!</p>
  
  <p>Page Name: PrintMyPDF.php</p>
  
  <pre><code>&lt;?php
  //error_reporting(E_ALL);  
  //ini_set('display_errors', 1);
  $thisorderID = $_GET['Xort'];
  
  require ('UFunctions.php');
  
  if (trim($thisorderID) == ""){
  $value = '0';
  }
  
  if (!is_digit($thisorderID) || $thisorderID &lt; 0)
  {
  header('Location:ErrorInt.php');
  exit;
  }
  
  //Database connection established
  require_once('DBASEConnector.php');
  
  $sql2 = "SELECT users.name, users.storenum, users.storename, Orders.OrderID, Orders.name
  FROM users, Orders
  WHERE Orders.name = users.name
  AND Orders.OrderID = '$thisorderID'";
  $result = $db-&gt;query($sql2);
  
  $row = $result-&gt;fetch_assoc();
  $ThisStoreNum = $row['storenum'];
  $ThisStoreName = $row['storename'];
  
  require('fpdf.php');
  
  $pdf = new FPDF();
  //$fpdf-&gt;SetMargins(0, 0, 0);
  //$fpdf-&gt;SetAutoPageBreak(true, 0);
  $pdf-&gt;SetAuthor('Walter Ballsbig');
  $pdf-&gt;SetTitle('Order Form');
  $pdf-&gt;SetFont('Helvetica','B',16);
  $pdf-&gt;SetTextColor(0,0,0);
  
  $pdf-&gt;AddPage('P');
  $pdf-&gt;SetDisplayMode(real,'default');
  
  $pdf-&gt;SetXY(50,20);
  $pdf-&gt;SetDrawColor(0,0,0);
  $pdf-&gt;Cell(100,10,'Order Form',1,1,'C',0);
  $pdf-&gt;SetFontSize(10);
  $pdf-&gt;SetX(50);
  $pdf-&gt;Cell(100,10, 'Order: '.$thisorderID.'  |  Store: '.$ThisStoreNum.'-'.$ThisStoreName,1,1,'C',0);
  
  
  $pdf-&gt;SetXY(10,50);
  $pdf-&gt;SetFontSize(12);
  $pdf-&gt;Cell(6,6,'X',1,0,'C',0);
  $pdf-&gt;Cell(14,6,'QTY',1,0,'C',0);
  $pdf-&gt;Cell(130,6, 'ITEM',1,0,'C',0);
  $pdf-&gt;Cell(30,6, 'UNIT',1,1,'C',0); 
  
  $query = "SELECT Inventory.ProductI, Inventory.ProductName, Inventory.CurrentQty, Inventory.Pull, Inventory.Unit, OrderItems.ProductI, OrderItems.QtyO, OrderItems.OrderI 
  FROM Inventory, OrderItems
  WHERE OrderItems.OrderI = '$thisorderID'
  AND OrderItems.ProductI = Inventory.ProductI
  ORDER BY Inventory.Pull, Inventory.ProductName";
  $result = $db-&gt;query($query);
  
  $num_results = $result-&gt;num_rows;
  
  for ($i=0; $i &lt;$num_results; $i++) 
  {
  $row = $result-&gt;fetch_assoc();
  
  $pdf-&gt;SetFontSize(12);
  
  IF ($row['CurrentQty'] &lt;=0)
  {
  $pdf-&gt;SetFontSize(10);
  $pdf-&gt;Cell(6,6,'BO',1,0,'C',0);
  $pdf-&gt;SetFontSize(12);
  }else{
  $pdf-&gt;Cell(6,6,' ',1,0,'C',0);
  }
  $pdf-&gt;Cell(14,6, $row['QtyO'],1,0,'C',0);
  $pdf-&gt;Cell(130,6, $row['ProductName'],1,0,'L',0);
  $pdf-&gt;Cell(30,6, $row['Unit'],1,1,'C',0);   
  }
  
  
  $pdf-&gt;Output();
  
  $db-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>This prints up my pdf beautifully! Now I wanted to add a barcode on the page that will represent the order number for scanning purposes.</p>
  
  <p>Now here is what I have for my code that contains the barcode... code.</p>
  
  <p>Name of barcode page: BarCodeIt.php</p>
  
  <pre><code>&lt;?php
  
  function BarCodeIt($MyID) {
  // Including all required classes
  require_once('./class/BCGFontFile.php');
  require_once('./class/BCGColor.php');
  require_once('./class/BCGDrawing.php');
  
  // Including the barcode technology
  require_once('./class/BCGcode39.barcode.php');
  
  // Loading Font
  $font = new BCGFontFile('./font/Arial.ttf', 18);
  
  // Don't forget to sanitize user inputs
  $text = isset($_GET['text']) ? $_GET['text'] : $MyID;
  
  // The arguments are R, G, B for color.
  $color_black = new BCGColor(0, 0, 0);
  $color_white = new BCGColor(255, 255, 255);
  
  $drawException = null;
  try {
  $code = new BCGcode39();
  $code-&gt;setScale(2); // Resolution
  $code-&gt;setThickness(30); // Thickness
  $code-&gt;setForegroundColor($color_black); // Color of bars
  $code-&gt;setBackgroundColor($color_white); // Color of spaces
  $code-&gt;setFont($font); // Font (or 0)
  $code-&gt;parse($text); // Text
  } catch(Exception $exception) {
  $drawException = $exception;
  }
  
  /* Here is the list of the arguments
  1 - Filename (empty : display on screen)
  2 - Background color */
  $drawing = new BCGDrawing('', $color_white);
  if($drawException) {
  $drawing-&gt;drawException($drawException);
  } else {
  $drawing-&gt;setBarcode($code);
  $drawing-&gt;draw();
  }
  
  //Header that says it is an image (remove it if you save the barcode to a file)
  header('Content-Type: image/png');
  header('Content-Disposition: inline; filename="barcode.png"');
  
  // Draw (or save) the image into PNG format.
  $drawing-&gt;finish(BCGDrawing::IMG_FORMAT_PNG);
  }
  ?&gt;
  </code></pre>
  
  <p>Now in my PDF file just before this line:</p>
  
  <pre><code>$pdf-&gt;Output();
  </code></pre>
  
  <p>I have added this:</p>
  
  <pre><code>$pdf-&gt;AddPage('P');
  $pdf-&gt;SetDisplayMode(real,'default');
  
  require('/BarCodeIt.php');
  
  $MyBarCode = BarCodeIt($thisorderID);
  echo $MyBarCode;
  </code></pre>
  
  <p>But what it does is all of my other pdf elements disappear and I'm left with only a big barcode (the right one! that part works) but that's all that is on the screen. It's like when the barcode section runs it negates everything else and just prints the barcode. I want to print just the barcode where I want it on the PDF but I'm not clever enough to figure out what I'm doing wrong. Any help on this would be greatly appreciated.</p>