Add gift message to Magento’s PDF packingslip

To be honest, I have never been working with gift messages in Magento, so I got very surprised once I saw that there is no output for it in any
document that customer recieves. This time I got request from client to write gift message on PDF packingslip.
Actually this is somewhat easy and goes like this…

1) Rewrite this class: Mage_Sales_Model_Order_Pdf_Shipment
Put this in your config.xml


Put file Shipment.php inside your module directory following the same directory structure like original file.
Class should look like this:

Yourfirm_Yourmodulename_Model_Order_Pdf_Shipment extends Mage_Sales_Model_Order_Pdf_Shipment  
// code from original class (I have removed it for readability purposes)
//add this method 
public function addGiftMsg($page, $giftMessageSender, $giftMessageNote) 
    	if(empty($giftMessageNote)) {
		$pipfmText = $giftMessageSender ."***BREAK***"."  "."***BREAK***".wordwrap($giftMessageNote, 100, "***BREAK***", true);
		$pipfmTextLines = array();
		$pipfmTextLines = explode("***BREAK***", $pipfmText);
		$i = 0;
		$pipfmTextLineStartY = 300;
		foreach ($pipfmTextLines as $pipfmTextLine) 
			$i ++;
			//Bold only the first line
			if($i == 1) 
				$this->_setFontBold_Modified($page, 10);
			} else {
				$this->_setFontRegular($page, 10);
			$page->drawText($pipfmTextLine, 60, $pipfmTextLineStartY, 'UTF-8');
			$pipfmTextLineStartY = $pipfmTextLineStartY - 10;	
// at some place where you want output (inside getPdf() method) for it just drop this lines:
public function getPdf($shipments = array())
       $giftMessage = Mage::getModel("giftmessage/message")->load($order->getGiftMessageId());
       $giftMessageSender ="Message from ".$giftMessage->getSender().':';
       $giftMessageNote = $giftMessage->getMessage();
       $this->addGiftMsg($page, $giftMessageSender, $giftMessageNote);

Please do not use this on production without testing it first.
If you have any questions, post it here, but please note that since this is not complete module, you will need to know some Magento basics to get it work.
I hope someone can find it useful.

About Tomas Novoselic

Backend Developer

At Inchoo, Tomas is backend developer, Certified Magento Developer who handles Magento modifications at any level. He also works closely with clients on Magento projects of any size and difficulty.

Read more posts by Tomas / Visit Tomas's profile


  1. Sorry, i have resolved the problem! I was working on a magento that already has overring that model!
    Sorry for loosing time!

  2. I have a question. I’m tring to override the model Mage_Sales_Model_Order_Pdf_Shipment but my class that extends i i not called.

    In the example above the new model (Yourfirm_Yourmodulename_Model_Order_Pdf_Shipment) is called every time the father model is colled or we can do manually? that is Mage::getModel(‘sales/order_pdf_shipment’) or Mage::getModel(‘Yourfirm_Yourmodulename_Model_Order_Pdf_Shipment’)?.

    Thank you

  3. Can the same practices be applied to adding gift messages to INVOICES?

    I tried modifying the above instructions to add the gift messages to invoices (since you can’t print packing slips until the order is marked as ‘complete’), but I only got as far as causing fatal errors upon attempting to print the invoice.

    (I did see you great post on printing custom attributes on invoices, but it didn’t seem as if that information could be applied to making gift messages display on the invoice).

    On a side note: THANK YOU for all of these great posts. I’m not super-comfortable with Magento (yet) and sometimes Magento makes me want to either A) weep softly or B) knock my brain against a wall.

  4. @Prajosh

    Do you mean this extension or any extension in general?
    Well, to shut down this one, all you need to do is to go to: /app/etc/modules/Yourfirm_Yourmodulename.xml and set active directive to false. Then you can safely remove /app/code/local/Yourfirm/Yourmodulename directory. Same procedure can be applied for every other extensions, however, if you don’t know what extension actually does to your system, maybe that’s not very good idea since there are lot of extensions that modify template files directly -.-, not to mention those that are making quite a mess in your database in most weird way you can imagine, but in general, you should be able to do what I described, but be careful and make backup of everything you change. I hope it helped!

  5. Great blog guys!

    How would I add more detail to this? For example a table with some custom attributes filled out? I would like to integrate a CN22 or customs declaration form onto my packing slips, rather than having to fill one out separately? Just fields like weight, and a jpeg of a signature…

  6. Thanks for the clean example Tomas. Yes, there is indeed a lot that one would expect as built in but then we discover that it is not.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.