Skip to main content
added 65 characters in body
Source Link

Try creating same methods which you want to override from AbstractPdf.php in your overided Invoice.php file. For example, if you want to change the font:

  1. Create a preference for Invoice.php in di.xml

<preference for="Magento\Sales\Model\Order\Pdf\Invoice" type="Vendor\Module\Model\Order\Pdf\Invoice" />

  1. In Vendor\Module\Model\Order\Pdf\Invoice, in you case create a function _setFontRegularmethod insertOrder

    /**

    • Set font as regularInsert order to pdf page
    • @param \Zend_Pdf_Page $object\Zend_Pdf_Page &$page
    • @param int $size\Magento\Sales\Model\Order $obj
    • @param bool $putOrderId
    • @return \Zend_Pdf_Resource_Fontvoid
    • @SuppressWarnings(PHPMD.CyclomaticComplexity)
    • @SuppressWarnings(PHPMD.NPathComplexity)
    • @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _setFontRegularinsertOrder($object&$page, $size$obj, $putOrderId = 7true) { $font = \Zend_Pdf_Font::fontWithPath( $this->getFontsDir() . ('your-font-name') ); $object->setFont($font, $size); return $font;// comment relevent code according to your requirement }

Try creating same methods which you want to override from AbstractPdf.php in your overided Invoice.php file. For example, if you want to change the font:

  1. Create a preference for Invoice.php in di.xml

<preference for="Magento\Sales\Model\Order\Pdf\Invoice" type="Vendor\Module\Model\Order\Pdf\Invoice" />

  1. In Vendor\Module\Model\Order\Pdf\Invoice, create a function _setFontRegular

    /**

    • Set font as regular
    • @param \Zend_Pdf_Page $object
    • @param int $size
    • @return \Zend_Pdf_Resource_Font */ protected function _setFontRegular($object, $size = 7) { $font = \Zend_Pdf_Font::fontWithPath( $this->getFontsDir() . ('your-font-name') ); $object->setFont($font, $size); return $font; }

Try creating same methods which you want to override from AbstractPdf.php in your overided Invoice.php file. For example:

  1. Create a preference for Invoice.php in di.xml

<preference for="Magento\Sales\Model\Order\Pdf\Invoice" type="Vendor\Module\Model\Order\Pdf\Invoice" />

  1. In Vendor\Module\Model\Order\Pdf\Invoice, in you case create a method insertOrder

    /**

    • Insert order to pdf page
    • @param \Zend_Pdf_Page &$page
    • @param \Magento\Sales\Model\Order $obj
    • @param bool $putOrderId
    • @return void
    • @SuppressWarnings(PHPMD.CyclomaticComplexity)
    • @SuppressWarnings(PHPMD.NPathComplexity)
    • @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function insertOrder(&$page, $obj, $putOrderId = true) { // comment relevent code according to your requirement }
Source Link

Try creating same methods which you want to override from AbstractPdf.php in your overided Invoice.php file. For example, if you want to change the font:

  1. Create a preference for Invoice.php in di.xml

<preference for="Magento\Sales\Model\Order\Pdf\Invoice" type="Vendor\Module\Model\Order\Pdf\Invoice" />

  1. In Vendor\Module\Model\Order\Pdf\Invoice, create a function _setFontRegular

    /**

    • Set font as regular
    • @param \Zend_Pdf_Page $object
    • @param int $size
    • @return \Zend_Pdf_Resource_Font */ protected function _setFontRegular($object, $size = 7) { $font = \Zend_Pdf_Font::fontWithPath( $this->getFontsDir() . ('your-font-name') ); $object->setFont($font, $size); return $font; }