Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 2
Change printed (pdf) Invoice font size
 
amalgamotion
Jr. Member
 
Total Posts:  22
Joined:  2009-01-22
 

What do I need to do to change the printed Invoice font size? I found the template for this page, (app/design/frontend/default/default/template/sales/print) but I don’t see a css reference.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageParts
Guru
 
Avatar
Total Posts:  415
Joined:  2007-11-18
 

I’m not 100% sure about this, I haven’t really got that much experience working with PDF generation using PHP. But I think you’ll need to take a look at the following files.

app/code/core/Sales/Model/Order/Pdf/Abstract.php (line 506-525)
app/code/core/Sales/Model/Order/Pdf/Invoice.php (line 44, 63 & 100)

I don’t think the css is taken into consideration here. Usually when you generate PDF’s on the fly everything is set directly in the PHP code. From these files you should also be able to manipulate colors, fonts and object positions in your PDF. Hope that helps ^^

Note: changes in the Abstract.php file will most likely have effects on other PDF’s printed from the order section. Such as credit memos and packing slips.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Micah_GT
Jr. Member
 
Total Posts:  22
Joined:  2009-01-29
 

I *just* figured this out today! I have my invoices completely redesigned using Helvetica and US Letter paper.

Here are the downsides.

1. These modifications WILL be overwritten if you try to upgrade.
2. This is a pain to do-- and a bit mathy.

But, the 3 files in question to customize the invoice PDF are:

/app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php
/app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php
/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php

If ALL you want to do is change the font size, then it’s quite easy. If, however, you want to change the font (I changed it to helvetica for a smaller PDF file size since Helvetica does not have to be embedded) or change the paper size to US Letter, then you have a lot of tweaking to do.

The PDFs are creating using Zend_Pdf. So it may be useful to look through http://framework.zend.com/apidoc/core/ (Select Zend_Pdf from the dropdown in the top right corner).

Let’s start with the font and/or font size. Start with /app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php. There are 3 private methods called _setFontRegular(), _setFontBold(), and _setFontItalic() which are used through Abstract.php as well as Invoice.php. Anytime you see a call to one of these 3 methods, that is where the font is being set for a particular bit of text. The second parameter is the size (default is 7pt). So, to change the font size, find the call you want and change the second parameter. For example, the insertAddress() method could be changed to $this->_setFontBold($page, 9) if you wanted a 9pt font.

Another thing you’ll need to realize, is that the measuments are all in points--not pixels. So, if you increase the font size, you may have to DECREASE the next y value since the coordinate system is x/y along the left and BOTTOM of the page.

To change the font, you would change the calls withing the _setFontXXXX() methods. They currently use Zend_Pdf_Font::fontWithPath() to specify a font (libertine) which is embedded in the PDF. If you want to use Helvetica to save file size, you can use Zend_Pdf_Font::fontWithName() instead. I changed mine to HELVETICA, HELVETICA_BOLD, and HELVETICA_BOLD_ITALIC. This way I get a smaller file size since I archive my invoices.

If you do change the font in /app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php, you must also do it in /app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php (Magento 1.2.1) since the item object has it’s own _setFontXXXX() methods.

Cheers.

 
Magento Community Magento Community
Magento Community
Magento Community
 
lriver
Jr. Member
 
Total Posts:  27
Joined:  2008-08-20
 

Do you know if it is possible to change the title of the PDF?  What I would like to do is to set it so that when you generate the Invoice PDF the document title is the order number.  That way when I save the file the default file name is the Order number.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Micah_GT
Jr. Member
 
Total Posts:  22
Joined:  2009-01-29
 

That part I do not know.

 
Magento Community Magento Community
Magento Community
Magento Community
 
amalgamotion
Jr. Member
 
Total Posts:  22
Joined:  2009-01-22
 

Thanks all for the help with this.

I’ve almost got the invoice formatted the way the client wants. The last thing I have to deal with is the Invoice, Order, Order Date block. The client would like the text in that block to be Black instead of the default White. I haven’t found the place in the code where the font color is set.

Anyone have any ideas what the font color lines look like?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Micah_GT
Jr. Member
 
Total Posts:  22
Joined:  2009-01-29
 

There are several places. I think the part you are looking for is in Abstract.php and is called something like insertOrder(). This is where the order # and invoice # are printed. There will be a call to $page->setFillColor() which is where the color is set before the calls to $page->drawText().

I changed my invoice and packing slips to only black and white (I have a crappy B&W;printer and wanted crisp clean printouts). So, I use Zend’s grayscale method:

$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));

You pass in a decimal to indicate the gray scale.... the 0 is black, 1 would be white, and 0.5 would be 50% gray. Remember to set this back to white after you draw the text so that the next rectangle is not drawn with a black fill color.

 
Magento Community Magento Community
Magento Community
Magento Community
 
amalgamotion
Jr. Member
 
Total Posts:  22
Joined:  2009-01-22
 

That did it. Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Armen
Member
 
Total Posts:  46
Joined:  2008-05-06
Los Angeles
 

This is yet another hacky pain point in Magento implementation but thanks to this thread and this wiki page (http://www.magentocommerce.com/wiki/how-to/editing_an_invoice_pdf) I was able to make enough changes to get our PDF’s using Letter size dimensions with legible font sizes, and using Helvetica to shrink the size of the PDF’s by about 1000%.

In my experience, bumping up the font sizes resulted in item table headings and item row prices to stretch past the correct alignment on the right side of the page. To fix the item row prices I was forced to edit one additional file: /magentodev/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php

Thanks for the help from the community.

 
Magento Community Magento Community
Magento Community
Magento Community
 
freshshop
Sr. Member
 
Avatar
Total Posts:  88
Joined:  2009-03-07
 

Hey guys,

really great information you have supplied. I didn’t think it was going to be a little more coding learning when it comes to changing the invoices…

as I am not so good at Zend language and have not more time I would like to ask if there is anybody who could give me the full codes for a simple legitible invoice format. I just want to make the size a bit bigger and if possible use Helvetica instead of Libertine because it creates really heavy files…

thanks in advance!

- will help with translations into Spanish and German if anyone would be in need! smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
thedust2020
Jr. Member
 
Total Posts:  12
Joined:  2008-11-21
 
Micah_GT - 10 February 2009 02:24 PM

I *just* figured this out today! I have my invoices completely redesigned using Helvetica and US Letter paper.

Here are the downsides.

1. These modifications WILL be overwritten if you try to upgrade.
2. This is a pain to do-- and a bit mathy.

But, the 3 files in question to customize the invoice PDF are:

/app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php
/app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php
/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php

If ALL you want to do is change the font size, then it’s quite easy. If, however, you want to change the font (I changed it to helvetica for a smaller PDF file size since Helvetica does not have to be embedded) or change the paper size to US Letter, then you have a lot of tweaking to do.

The PDFs are creating using Zend_Pdf. So it may be useful to look through http://framework.zend.com/apidoc/core/ (Select Zend_Pdf from the dropdown in the top right corner).

Let’s start with the font and/or font size. Start with /app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php. There are 3 private methods called _setFontRegular(), _setFontBold(), and _setFontItalic() which are used through Abstract.php as well as Invoice.php. Anytime you see a call to one of these 3 methods, that is where the font is being set for a particular bit of text. The second parameter is the size (default is 7pt). So, to change the font size, find the call you want and change the second parameter. For example, the insertAddress() method could be changed to $this->_setFontBold($page, 9) if you wanted a 9pt font.

Another thing you’ll need to realize, is that the measuments are all in points--not pixels. So, if you increase the font size, you may have to DECREASE the next y value since the coordinate system is x/y along the left and BOTTOM of the page.

To change the font, you would change the calls withing the _setFontXXXX() methods. They currently use Zend_Pdf_Font::fontWithPath() to specify a font (libertine) which is embedded in the PDF. If you want to use Helvetica to save file size, you can use Zend_Pdf_Font::fontWithName() instead. I changed mine to HELVETICA, HELVETICA_BOLD, and HELVETICA_BOLD_ITALIC. This way I get a smaller file size since I archive my invoices.

If you do change the font in /app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php, you must also do it in /app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php (Magento 1.2.1) since the item object has it’s own _setFontXXXX() methods.


Cheers.

I’ve followed these instructions but can’t get the text size of the invoice items to change it all.  It looks like they are rendered via the “drawItem” function.  There’s nothing in there referring to the “setFont” functions.  I’ve tried inserting my own calls to no avail.  Anyone have advice on this?  It seems I can’t change anything below the line that reads “Products”, “SKU”, “Price”, etc.

 
Magento Community Magento Community
Magento Community
Magento Community
 
irideflatland
Member
 
Avatar
Total Posts:  41
Joined:  2009-10-20
 
thedust2020 - 29 October 2009 02:39 PM

I’ve followed these instructions but can’t get the text size of the invoice items to change it all.  It looks like they are rendered via the “drawItem” function.  There’s nothing in there referring to the “setFont” functions.  I’ve tried inserting my own calls to no avail.  Anyone have advice on this?  It seems I can’t change anything below the line that reads “Products”, “SKU”, “Price”, etc.

I’m wondering the same thing. I got the address and payment method etc fonts to change, but not the actual list of items.

 
Magento Community Magento Community
Magento Community
Magento Community
 
thedust2020
Jr. Member
 
Total Posts:  12
Joined:  2008-11-21
 

Now I’m really confused.  Basically nothing I’m doing to these files is having any effect on the invoices whatsoever.  I’ve even tried deleting them and still the invoices are just generating as usual, with half of the information being overlapped with over sections and not readable.

The files:

/app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php
/app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php
/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php

Can someone clarify how the invoices are cached in the system?  I’ve tried clearing the cache, deleting these files and still the crappy looking invoices are being generated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
GreeNoodle
Jr. Member
 
Total Posts:  12
Joined:  2010-02-18
 

I’ve followed these instructions but can’t get the text size of the invoice items to change it all.  It looks like they are rendered via the “drawItem” function.  There’s nothing in there referring to the “setFont” functions.  I’ve tried inserting my own calls to no avail.  Anyone have advice on this?  It seems I can’t change anything below the line that reads “Products”, “SKU”, “Price”, etc.

Me too. Can someone PLEASE help me figure out how to increase the font size for products, sku, price?

 
Magento Community Magento Community
Magento Community
Magento Community
 
RSA Interactive
Jr. Member
 
Total Posts:  2
Joined:  2009-04-29
 

To change the font size for the list of purchased items (below “Products/SKU/Price/etc.") I did this:

in /app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php , line 687 is…

$fontSize  = empty($column['font_size']) ? $column['font_size'];

Change the number after the “?” to the size you want.

To change the font size of the shipping and totals I did this:

in /app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php , line 411-426 is…

$lineBlock['lines'][] = array(
                    array(
                        
'text'      => $label,
                        
'feed'      => 475,
                        
'align'     => 'right',
                        
'font_size' => $fontSize,
                        
'font'      => 'bold'
                    
),
                    array(
                        
'text'      => $amount,
                        
'feed'      => 565,
                        
'align'     => 'right',
                        
'font_size' => $fontSize,
                        
'font'      => 'bold'
                    
),
                );

I just changed $fontSize to the size I wanted. The $fontSize definition is right above this block of code, but changing that didn’t seem to work, so I manually plugged in the numbers. Meh. Hope this helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
smallsmartass
Jr. Member
 
Total Posts:  29
Joined:  2009-10-07
 

The font size for the totals is set in the config.xml file for the Sale module. If you look at app/code/core/Mage/Sales/etc/config.xml on line 656 you’ll see a node for each kind of total. I have no clue why they hid it in there. It looks like they might have been thinking about letting us modify the font sizes in the admin panel, which would make total sense, but didn’t for some reason.

If you used an override to customize Invoice.php or any of the other PDF files that aren’t Abstract.php then you can just copy the pdf node into the config.xml file for your local copy of the Sales module.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2