In invoice the contents are not aligned [closed]
-
07-10-2020 - |
Question
My first problem regarding the invoice is solved when I used DejaVuSans.ttf font instead of Magento default font that removes the boxes that are hiding the Rupee Signs. My new problem is, the SKU number, Price, Qty, Tax, Subtotal of the product is not coming aligned below their respective headers in invoice when i downloaded the invoice from the admin panel by clicking on Print button. All info are coming slightly moved towards to its right. I attached the screenshot for proper understanding. Still this issue is not solved.
Solution
Magento uses the Linux Libertine True Type Font to create the PDF.
It is defined in
app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php
in 3 instances, near lines 793,807 and 821
Unfortunately this font does not have the Indian rupee sign glyph (U+20B9) !!
That is why you get these boxes.
You can replace the font with one that does have the glyph. I'm not an expert but using a charachter map I found that arial does have the charachter (U+20B9)
In order to do that, first copy
app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php
to
app/code/local/Mage/Sales/Model/Order/Pdf/Abstract.php
You will be editing this new file. You have two options either upload your own font or use a built-in one.
1. Using built-in font
Replace the following three lines respectevily:
$font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Re-4.4.1.ttf');
with
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
$font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Bd-2.8.1.ttf');
with
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD);
$font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_It-2.8.2.ttf');
with
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_ITALIC);
2. Uploading your own font
upload your font on any dir on your derver, preferably in /lib/my_font/ then tweak the three paths mentioned above to use your files.
for example, change
$font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Re-4.4.1.ttf');
to
$font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/my_font/MyFontRegular.ttf');