0

I have already customized the pdf invoice i.e

PdfInvoice/InvoiceChange/etc/adminhtml/di.xml PdfInvoice/InvoiceChange/etc/module.xml PdfInvoice/InvoiceChange/Model/Order/Pdf/Invoice.php PdfInvoice/InvoiceChange/registration.php

So similarly, I changed pdf shipment packing slip also tried but in the invoice place, I overrode AbstractPdf file but not working please tell me, anyone?

PdfShipment/ShipmentChange/etc/adminhtml/di.xml

 <preference for="Magento\Sales\Model\Order\Pdf\AbstractPdf" type="PdfShipment\ShipmentChange\Model\Order\Pdf\AbstractPdf"/>  

PdfShipment/ShipmentChange/etc/module.xml

<module name="PdfShipment_ShipmentChange" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Sales"/>
        </sequence>
    </module>  

PdfShipment/ShipmentChange/Model/Order/Pdf/AbstractPdf.php

protected function _setFontBold($object, $size = 7)
    {
        $font = \Zend_Pdf_Font::fontWithPath(
            $this->_rootDirectory->getAbsolutePath('lib/internal/montserrat/Montserrat-Bold.ttf')
        );
        $object->setFont($font, $size);
        return $font;
    }
  • In the di.xml <?xml version="1.0"?> <config xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Sales\Model\Order\Pdf\Invoice" type="PdfInvoice\InvoiceChange\Model\Order\Pdf\Invoice" /> </config> – Parshuram May 7 '19 at 7:29
  • In the module.xml <?xml version="1.0"?> <config xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="PdfInvoice_InvoiceChange" setup_version="1.0.0"> <sequence> <module name="Magento_Sales"/> </sequence> </module> </config> – Parshuram May 7 '19 at 7:29
  • in the registration.php <?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'PdfInvoice_InvoiceChange', DIR ); – Parshuram May 7 '19 at 7:30
  • in the Invoice.php protected function _setFontRegular($object, $size = 7) { $font = \Zend_Pdf_Font::fontWithPath( $this->_rootDirectory->getAbsolutePath('lib/internal/montserrat/Montserrat-Regular.ttf') ); $object->setFont($font, $size); return $font; } – Parshuram May 7 '19 at 7:37
  • so similarly how to do that pdf shipping packing slip font? – Parshuram May 7 '19 at 7:37
0

To edit the packing list, or any other PDF docs such as invoice you need to override the files contained within

Magento\Sales\Model\Order\Pdf

For example if wanted to add the price to the packing list

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <preference for="Magento\Sales\Model\Order\Pdf\Items\Shipment\DefaultShipment"
                type="Example\Sales\Model\Order\Pdf\Items\Shipment\DefaultShipment"/>

</config>

Then copy the file "Magento\Sales\Model\Order\Pdf\Items\Shipment\DefaultShipment" to your app/code file, change the name spacing to match the XML above and add the following on around line number 81

 // draw item Prices
        $i = 0;
        $prices = $this->getItemPricesForDisplay();
        $feedPrice = 395;
        $feedSubtotal = $feedPrice + 70;
        $feedTax = $feedSubtotal + 70;
        foreach ($prices as $priceData) {
            if (isset($priceData['label'])) {
                // draw Price label
                $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
                // draw Subtotal label
                $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
                $i++;
            }
            // draw Price
            $lines[$i][] = [
                'text' => $priceData['price'],
                'feed' => $feedPrice,
                'font' => 'bold',
                'align' => 'right',
            ];
            // draw Subtotal
            $lines[$i][] = [
                'text' => $priceData['subtotal'],
                'feed' => $feedSubtotal,
                'font' => 'bold',
                'align' => 'right',
            ];
            $i++;
        }

        // draw Tax
        $lines[0][] = [
            'text' => $order->formatPriceTxt($item->getTaxAmount()),
            'feed' => $feedTax,
            'font' => 'bold',
            'align' => 'right',
        ];
| improve this answer | |
  • please attach this code – Rk Rathod May 7 '19 at 11:59
  • ok i changed the di.xml filename but it is not working – Parshuram May 7 '19 at 12:01
  • any error?????? – Rk Rathod May 7 '19 at 12:02
  • which file you want to override ?? – Rk Rathod May 7 '19 at 12:03
  • I am overriding AbstractPdf.php but code changes are not reflecting when i am downloading the pdf file.The generated pdf file have default styles not modified one – Parshuram May 7 '19 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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