I am using an extension to add additional fee on Cash on Delivery payment gateway.

It is working fine but the COD fee is not showing in invoice pdf.

This issue only for the admin invoice pdf.

How can I add this information in pdf?


2 Answers 2


create pdf.xml file under etc folder

add add below code

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/pdf_file.xsd">
    <total name="cgst">
      <title translate="true">Cgst</title>

change code as per your need

  • Not working, I have added pdf.xml in the module. But the COD fee is not showing. Mar 20, 2018 at 9:53
  • there is a column of codcharge is you invoice table or not?? Mar 20, 2018 at 9:57
  • its working for me in my GST extension Mar 20, 2018 at 9:58
  • In my case, COD charge is 'cash_on_delivery_fee' in the table Mar 20, 2018 at 9:59
  • does you add any field in Invoice table or not??? Mar 20, 2018 at 9:59

You are required to create model: Name_space/module_name/Model/Sales/Pdf/Customfee.php

namespace Name_space\module_name\Model\Sales\Pdf;

class Customfee extends \Magento\Sales\Model\Order\Pdf\Total\DefaultTotal
    public function getTotalsForDisplay()
        $order =  $this->getOrder();
       $amount = $order->getCash_on_delivery_fee(); // 'Cash_on_delivery_fee' replace with your custom attribute 

        $title = __($this->getTitle());
        if ($this->getTitleSourceField()) {
            $label = $title . ' (' . $this->getTitleDescription() . '):';
        } else {
            $label = $title . ':';

        $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
        $total = ['amount' => '₹'.number_format($amount,2), 'label' => 'Cash on Delivery Charges', 'font_size' => $fontSize];
        return [$total];

Your Answer

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

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