Magento – Adding a barcode for Order number and Tracking Number in Shipment PDF

barcodeshipmentshipment-tracking

I am trying to add bar codes for the order number and tracking number in the shipment PDF.
Can anyone help?

Thanks!

Best Answer

You have two requirements here - 1) adding a barcode and 2) adding a tracking number.

Barcode:

Barcodes typically require custom fonts. How are you generating barcodes today? If you find yourself using an external service to render the barcode you can create the image offline and include. Using the font is more complex than the image as you must define a path to font on the server.

This is a good example of the type of work required in a custom module that extends Mage_Sales_Model_Order_Pdf_Packaging:

/* Define a font path that is readable by the web server */
$fontPath = '/var/www/barcode-fonts/FRE3OF9X.TTF';

/* Load the font */
$page->setFont(Zend_Pdf_Font::fontWithPath($fontPath), 36);

/* Create barcode string. */
/* Note: Asterisks are required for code39 */
$barcodeImage = "*".$order->getIncrementId()."*";

/* Insert the barcode into the page */
$page->drawText($barcodeImage, 400, 800);

Source: http://www.magentocommerce.com/boards/viewthread/15807/

Tracking Number:

Adding the tracking number should be trivial compared to the above solution. The below solution lists tracking number separated 200px vertically from each other. In the same file as the barcode solution above:

  $x = 400; $y = 800;
  foreach($shipment->getTracksCollection() as $track){
        /* Insert the tracking code into the page */
        $page->drawText($track->getNumber(), $x, $y+=200);
  }

3rd party plugin

There are third-party plugins available that allow you to create more flexible Packing Slip templates, etc. - many have barcodes built in. Here's one:

http://www.magentocommerce.com/magento-connect/moogento-pickpack-pick-lists-packing-sheets-invoices-pdfs-fully-customisable-works-with-all-order-statuses.html

Good luck!

Related Topic