8

i want to customized the Invoice PDF layout like in the image this is just a example of print invoice pdf & changes i want how to change PDF invoice layout

4 Answers 4

11

http://inchoo.net/magento/how-to-add-custom-attribute-to-magentos-pdf-invoice/

other wise you can modify the following files putting into local code pool.

 /app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php
 /app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php
1
  • Always add the relevant information from a linked site into your post, in case when the link dies.
    – Black
    Jul 2, 2020 at 11:49
3

This can be achieved by modifying this file.

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

Please do not directly modify this file. Best way is to override this file first and then make modifications.

Thanks.

5
  • thanks, how can i override this file to make modification
    – Dinesh
    Oct 28, 2014 at 18:36
  • The easiest but not the best method is to create identical folder structure in your local folder and paste the file there and make modification. Like app/code/local/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php. The better approach is to make your own module and override this class. You can refer to the following document for your reference magedev.com/magento-overriding-model-block-or-helper Oct 29, 2014 at 9:53
  • Nasir Perwaiz it create problem when we update magento
    – Dinesh
    Oct 29, 2014 at 10:02
  • Yes, you are right. That's why I suggested you make your own module and override the class. Oct 29, 2014 at 10:04
  • Nasir Perwaiz i try edit pdf invoice by edit app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php but no result
    – Dinesh
    Nov 3, 2014 at 6:13
3

I have used the above answers with a combination of Zend_Pdf module (https://framework.zend.com/manual/1.12/en/zend.pdf.usage.html) to create some extra space and lines between the items in the Pdf invoice that Magento is producing, first here are the current Magento and Server information:
Magento Ver. 1.9.2.3
LAMP installation

Steps:

  1. Create a local duplicate of the following files:

    • code/core/Mage/Sales/Model/Order/Pdf/Abstract.php
      to
      code/local/Mage/Sales/Model/Order/Pdf/Abstract.php
    • code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php
      to
      code/local/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php
  2. Create an extra space between line items:
    Edit the Default.php file which is called every time an item is added to the pdf page so I've added an extra "empty" line after the item is added look for around line(141):

    $lineBlock = array(
        'lines'  => $lines,
        'height' => 20
    );
    $page = $pdf->drawLineBlocks($page, array($lineSpace), array('table_header' => true));
    

replace with:

    $lineBlock = array(
        'lines'  => $lines,
        'height' => 20
    );

    /* Modification to add line space between each row */
    $lineso[0][] = array(
        'text'  => '',
        'feed'  => 290,
        'align' => 'right'
    );
    // you can increase the line height by increasing the number on the line below 'height' =20
    $lineSpace = array(
        'lines' => $lineso,
        'height' =>20
    );

    $page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
    $page = $pdf->drawLineBlocks($page, array($lineSpace), array('table_header' => true));
  1. Create line separating each item after the space:
    Edit Abstract.php file which contains the functions that build up the PDF invoice file, we are looking for drawLineBlocks function which is executed every time a line is added to the PDF file, in here I've add a condition to look for empty line (spaces) which was added from the Default.php file and if they are found then we add a line below the space. Look for Around line(979):

$page->drawText($part, $feed, $this->y-$top, 'UTF-8');

Replace with:

$page->drawText($part, $feed, $this->y-$top, 'UTF-8');
                    if ($part ==''){
                        $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
                        $page->setLineWidth(0.5);
                        $page->drawLine(35, $this->y-$top, 570, $this->y-$top);
                    }

refresh cache, go to invoice on your admin and print it out to see the results.

1

It's not so easy task to do. Above mentioned article for custom attributes can solve your problem when it comes to adding new attributes to magento pdf invoice.

When it comes to layout and spacing in the pdf invoice, you will need to make changes in Invoice and Abstract.php

If you read thoose files you will see that the distances of pdf invoice rows and tables are declared with distance from x and y asis, so you will need to edit that values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.