how to edit Invoice pdf in magento 2.3Change title invoice pdfadd to footer image in adminpage pdf invoiceHow to can I add some text in invoice pdf magento?External link to Magento invoice PDF?Magento : Get Invoice PDF Link on Frontend Customer DashboardHow to get product image & remove background color on PDF invoice Magento 2.x?How can I customise the comparison PDF of Magento 2.1 PDF invoice layoutMagento 2: Set table structure in order invoice pdfRearrange the position of subtotal,shipment,tax in pdf invoice magento 2How to hide credit card details on invoice PDF?
Why isn't there a serious attempt at creating a third mass-appeal party in the US?
How do I stop my characters falling in love?
What is the most efficient way to write 'for' loops in Matlab?
Polyhedra, Polyhedron, Polytopes and Polygon
Can anyone give a concrete example to illustrate what is an uniform prior?
How many oliphaunts died in all of the Lord of the Rings battles?
Sea level static test of an upper stage possible?
What is the most common end of life issue for a car?
Decreasing star count
How do I explain an exponentially complex intuitively?
Why force the nose of 737 Max down in the first place?
Why do planes need a roll motion?
Why does Canada require mandatory bilingualism in all government posts?
What do you call a flexible diving platform?
How can religions be structured in ways that allow inter-faith councils to work?
How to apply the changes to my `.zshrc` file after edit?
Unethical behavior : should I report it?
Trapped in an ocean Temple in Minecraft?
How did Mysterio have these drones?
Send a single HTML email from Thunderbird, overriding the default "plain text" setting
May a man marry the women with whom he committed adultery?
Suggestions for protecting jeans from saddle clamp bolt
Which approach can I use to generate text based on multiple inputs?
Is it dangerous to add a custom cert authority to a browser?
how to edit Invoice pdf in magento 2.3
Change title invoice pdfadd to footer image in adminpage pdf invoiceHow to can I add some text in invoice pdf magento?External link to Magento invoice PDF?Magento : Get Invoice PDF Link on Frontend Customer DashboardHow to get product image & remove background color on PDF invoice Magento 2.x?How can I customise the comparison PDF of Magento 2.1 PDF invoice layoutMagento 2: Set table structure in order invoice pdfRearrange the position of subtotal,shipment,tax in pdf invoice magento 2How to hide credit card details on invoice PDF?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to edit my invoice PDF in magento 2.3, In below mentioned image. the 'red' bordered section move top on 'green' bordered section (Change Position). how to achieve my requirement ?
magento2.3 invoice pdf invoice-pdf
add a comment |
I want to edit my invoice PDF in magento 2.3, In below mentioned image. the 'red' bordered section move top on 'green' bordered section (Change Position). how to achieve my requirement ?
magento2.3 invoice pdf invoice-pdf
Can you please add again your screenshot?
– Sweety Masmiya
Jul 18 at 4:57
@Sweety Masmiya for what ? you need any clarification ?
– Shafeel Sha
Jul 18 at 5:01
Your image is not display. prnt.sc/oglshg
– Sweety Masmiya
Jul 18 at 5:05
oh sorry please check now, or follow i.stack.imgur.com/tqjMf.jpg
– Shafeel Sha
Jul 18 at 5:06
add a comment |
I want to edit my invoice PDF in magento 2.3, In below mentioned image. the 'red' bordered section move top on 'green' bordered section (Change Position). how to achieve my requirement ?
magento2.3 invoice pdf invoice-pdf
I want to edit my invoice PDF in magento 2.3, In below mentioned image. the 'red' bordered section move top on 'green' bordered section (Change Position). how to achieve my requirement ?
magento2.3 invoice pdf invoice-pdf
magento2.3 invoice pdf invoice-pdf
edited Jul 18 at 5:05
Shafeel Sha
asked Jul 18 at 4:31
Shafeel ShaShafeel Sha
19213 bronze badges
19213 bronze badges
Can you please add again your screenshot?
– Sweety Masmiya
Jul 18 at 4:57
@Sweety Masmiya for what ? you need any clarification ?
– Shafeel Sha
Jul 18 at 5:01
Your image is not display. prnt.sc/oglshg
– Sweety Masmiya
Jul 18 at 5:05
oh sorry please check now, or follow i.stack.imgur.com/tqjMf.jpg
– Shafeel Sha
Jul 18 at 5:06
add a comment |
Can you please add again your screenshot?
– Sweety Masmiya
Jul 18 at 4:57
@Sweety Masmiya for what ? you need any clarification ?
– Shafeel Sha
Jul 18 at 5:01
Your image is not display. prnt.sc/oglshg
– Sweety Masmiya
Jul 18 at 5:05
oh sorry please check now, or follow i.stack.imgur.com/tqjMf.jpg
– Shafeel Sha
Jul 18 at 5:06
Can you please add again your screenshot?
– Sweety Masmiya
Jul 18 at 4:57
Can you please add again your screenshot?
– Sweety Masmiya
Jul 18 at 4:57
@Sweety Masmiya for what ? you need any clarification ?
– Shafeel Sha
Jul 18 at 5:01
@Sweety Masmiya for what ? you need any clarification ?
– Shafeel Sha
Jul 18 at 5:01
Your image is not display. prnt.sc/oglshg
– Sweety Masmiya
Jul 18 at 5:05
Your image is not display. prnt.sc/oglshg
– Sweety Masmiya
Jul 18 at 5:05
oh sorry please check now, or follow i.stack.imgur.com/tqjMf.jpg
– Shafeel Sha
Jul 18 at 5:06
oh sorry please check now, or follow i.stack.imgur.com/tqjMf.jpg
– Shafeel Sha
Jul 18 at 5:06
add a comment |
2 Answers
2
active
oldest
votes
Create custom module with below step.
step1 : di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice" type="AdamsmageTaxModelOrderPdfItemsInvoiceDefaultInvoice" />
<preference for="MagentoSalesModelOrderPdfInvoice" type="AdamsmageTaxModelOrderPdfInvoice" />
Step2 : copied the functions that i wanted to override of the abstract class in appcodeAdamsmageTaxModelOrderPdfInvoice.php
like one thing i wanted to change was fonts
/**
* 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() . ('dejavu-sans/DejaVuSansCondensed.ttf')
);
$object->setFont($font, $size);
return $font;
/**
* Set font as bold
*
* @param Zend_Pdf_Page $object
* @param int $size
* @return Zend_Pdf_Resource_Font
*/
protected function _setFontBold($object, $size = 6)
$font = Zend_Pdf_Font::fontWithPath(
$this->getFontsDir() . ('dejavu-sans/DejaVuSansCondensed-Bold.ttf')
);
$object->setFont($font, $size);
return $font;
/**
* Set font as italic
*
* @param Zend_Pdf_Page $object
* @param int $size
* @return Zend_Pdf_Resource_Font
*/
protected function _setFontItalic($object, $size = 7)
$font = Zend_Pdf_Font::fontWithPath(
$this->getFontsDir() . ('dejavu-sans/DejaVuSans-Oblique.ttf')
);
$object->setFont($font, $size);
return $font;
Step3 : modify to Insertorder
protected function insertOrder(&$page, $obj, $putOrderId = true)
if ($obj instanceof MagentoSalesModelOrder)
$shipment = null;
$order = $obj;
elseif ($obj instanceof MagentoSalesModelOrderShipment)
$shipment = $obj;
$order = $shipment->getOrder();
$sellerId=$order->getData('seller_id');
$sellerInfo=$this->_taxHelper->getSellerAdressWithDetails($sellerId);
$this->y = $this->y ? $this->y : 815;
$top = $this->y;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->drawRectangle(25, $top, 570, $top - 55);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->setDocHeaderCoordinates([25, $top, 570, $top - 55]);
$this->_setFontRegular($page, 10);
if ($putOrderId)
$page->drawText(__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8');
$page->drawText(
__('Order Date: ') .
$this->_localeDate->formatDate(
$this->_localeDate->scopeDate(
$order->getStore(),
$order->getCreatedAt(),
true
),
IntlDateFormatter::MEDIUM,
false
),
35,
$top -= 15,
'UTF-8'
);
$top -= 10;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 570, $top - 25);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold By:'), 35, $top - 15, 'UTF-8');
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - 80);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach(explode("n", $sellerInfo) as $textLine)
if ($textLine!=='')
$page->drawText(strip_tags(ltrim($textLine)), 35, $this->y, 'UTF-8');
$this->y -=14;
$addressesEndY = $this->y;
$top -= 120;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 275, $top - 25);
$page->drawRectangle(275, $top, 570, $top - 25);
/* Calculate blocks info */
/* Billing Address */
$billingAddress = $this->_formatAddress($this->addressRenderer->format($order->getBillingAddress(), 'pdf'));
/* Payment */
$paymentInfo = $this->_paymentData->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf();
$paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
$payment = explode('pdf_row_separator', $paymentInfo);
foreach ($payment as $key => $value)
if (strip_tags(trim($value)) == '')
unset($payment[$key]);
reset($payment);
/* Shipping Address and Method */
if (!$order->getIsVirtual())
/* Shipping Address */
$shippingAddress = $this->_formatAddress($this->addressRenderer->format($order->getShippingAddress(), 'pdf'));
$shippingMethod = $order->getShippingDescription();
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold to:'), 35, $top - 15, 'UTF-8');
if (!$order->getIsVirtual())
$page->drawText(__('Ship to:'), 285, $top - 15, 'UTF-8');
else
$page->drawText(__('Payment Method:'), 285, $top - 15, 'UTF-8');
$addressesHeight = $this->_calcAddressHeight($billingAddress);
if (isset($shippingAddress))
$addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress));
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - $addressesHeight);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach ($billingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 45, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = $this->y;
if (!$order->getIsVirtual())
$this->y = $addressesStartY;
foreach ($shippingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 45, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = min($addressesEndY, $this->y);
$this->y = $addressesEndY;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $this->y, 275, $this->y - 25);
$page->drawRectangle(275, $this->y, 570, $this->y - 25);
$this->y -= 15;
$this->_setFontBold($page, 12);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$page->drawText(__('Payment Method'), 35, $this->y, 'UTF-8');
$page->drawText(__('Shipping Method:'), 285, $this->y, 'UTF-8');
$this->y -= 10;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->_setFontRegular($page, 10);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$paymentLeft = 35;
$yPayments = $this->y - 15;
else
$yPayments = $addressesStartY;
$paymentLeft = 285;
foreach ($payment as $value)
if (trim($value) != '')
//Printing "Payment comments" lines
$value = preg_replace('/<br[^>]*>/i', "n", $value);
foreach ($this->string->split($value, 45, true, true) as $_value)
if($_value=='No value')
$_value='No pay';
$page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8');
$yPayments -= 15;
if ($order->getIsVirtual())
// replacement of Shipments-Payments rectangle block
$yPayments = min($addressesEndY, $yPayments);
$page->drawLine(25, $top - 25, 25, $yPayments);
$page->drawLine(570, $top - 25, 570, $yPayments);
$page->drawLine(25, $yPayments, 570, $yPayments);
$this->y = $yPayments - 15;
else
$topMargin = 15;
$methodStartY = $this->y;
$this->y -= 15;
foreach ($this->string->split($shippingMethod, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$yShipments = $this->y;
$totalShippingChargesText = "(" . __(
'Total Shipping Charges'
) . " " . $order->formatPriceTxt(
$order->getShippingAmount()
) . ")";
$page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8');
$yShipments -= $topMargin + 10;
$tracks = [];
if ($shipment)
$tracks = $shipment->getAllTracks();
if (count($tracks))
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineWidth(0.5);
$page->drawRectangle(285, $yShipments, 510, $yShipments - 10);
$page->drawLine(400, $yShipments, 400, $yShipments - 10);
//$page->drawLine(510, $yShipments, 510, $yShipments - 10);
$this->_setFontRegular($page, 9);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
//$page->drawText(__('Carrier'), 290, $yShipments - 7 , 'UTF-8');
$page->drawText(__('Title'), 290, $yShipments - 7, 'UTF-8');
$page->drawText(__('Number'), 410, $yShipments - 7, 'UTF-8');
$yShipments -= 20;
$this->_setFontRegular($page, 8);
foreach ($tracks as $track)
$maxTitleLen = 45;
$endOfTitle = strlen($track->getTitle()) > $maxTitleLen ? '...' : '';
$truncatedTitle = substr($track->getTitle(), 0, $maxTitleLen) . $endOfTitle;
$page->drawText($truncatedTitle, 292, $yShipments, 'UTF-8');
$page->drawText($track->getNumber(), 410, $yShipments, 'UTF-8');
$yShipments -= $topMargin - 5;
else
$yShipments -= $topMargin - 5;
$currentY = min($yPayments, $yShipments);
// replacement of Shipments-Payments rectangle block
$page->drawLine(25, $methodStartY, 25, $currentY);
//left
$page->drawLine(25, $currentY, 570, $currentY);
//bottom
$page->drawLine(570, $currentY, 570, $methodStartY);
//right
$this->y = $currentY;
$this->y -= 15;
if you want to change another than check with below file.app/code/Magento/Sales/Model/Order/Pdf/Invoice.php
or vendor/magento/module-sales/Model/Order/Pdf/Invoice.php
Thank you fir your replay
– Shafeel Sha
Jul 18 at 6:05
Undefined property: ModelOrderPdfInvoice::$_taxHelper in /Model/Order/Pdf/Invoice.php on line 618 , error appears
– Shafeel Sha
Jul 18 at 6:05
try with clear cache and other basic commands. if than not working then please add code inside construct public function __construct(MagentoCatalogHelperData $taxHelper) $this->_taxHelper = $taxHelper;
– Anas Mansuri
Jul 18 at 6:14
add a comment |
override of the abstract class in
appcodeVendorModuleModelOrderPdfInvoice.php
In my case i'm hide that 'red boarded table and update below function insertOrderCustom and adjust element positions via changing $top variable values also comment drawLine codes ,if you need customize below coses basis on your requirement.
protected function insertOrderCustom(&$page, $obj, $putOrderId = true)
if ($obj instanceof MagentoSalesModelOrder)
$shipment = null;
$order = $obj;
elseif ($obj instanceof MagentoSalesModelOrderShipment)
$shipment = $obj;
$order = $shipment->getOrder();
$this->y = $this->y ? $this->y : 815;
$top = $this->y;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->drawRectangle(25, $top, 570, $top - 65);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->setDocHeaderCoordinates([25, $top, 570, $top - 55]);
$this->_setFontRegular($page, 10);
if ($putOrderId)
$page->drawText(__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8');
$page->drawText(
__('Order Date: ') .
$this->_localeDate->formatDate(
$this->_localeDate->scopeDate(
$order->getStore(),
$order->getCreatedAt(),
true
),
IntlDateFormatter::MEDIUM,
false
),
35,
$top -= 15,
'UTF-8'
);
$gstin = $this->_scopeConfig->getValue(
"gst/codilar/gstin",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
if (strlen($gstin)>0)
//$page->drawText(__('GSTIN : ') . $gstin, 35, $top -= 15, 'UTF-8');
$top -= 10;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 275, $top - 25);
$page->drawRectangle(275, $top, 570, $top - 25);
/* Calculate blocks info */
/* Billing Address */
$billingAddress = $this->_formatAddress($this->addressRenderer->format($order->getBillingAddress(), 'pdf'));
$gstin = 'GSTIN: '.$order->getBillingAddress()->getData('gstin');
if($gstin != null)
array_push($billingAddress,$gstin);
/* Payment */
$paymentInfo = $this->_paymentData->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf();
$paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
$payment = explode('pdf_row_separator', $paymentInfo);
foreach ($payment as $key => $value)
if (strip_tags(trim($value)) == '')
unset($payment[$key]);
reset($payment);
/* Shipping Address and Method */
if (!$order->getIsVirtual())
/* Shipping Address */
$shippingAddress = $this->_formatAddress($this->addressRenderer->format($order->getShippingAddress(), 'pdf'));
$shippingMethod = $order->getShippingDescription();
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold to:'), 35, $top - 15, 'UTF-8');
if (!$order->getIsVirtual())
$page->drawText(__('Ship to:'), 285, $top - 15, 'UTF-8');
else
$page->drawText(__('Payment Method:'), 285, $top - 15, 'UTF-8');
$addressesHeight = $this->_calcAddressHeight($billingAddress);
if (isset($shippingAddress))
$addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress));
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - $addressesHeight);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach ($billingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 40, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = $this->y;
if (!$order->getIsVirtual())
$this->y = $addressesStartY;
foreach ($shippingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 40, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = min($addressesEndY, $this->y);
$this->y = $addressesEndY;
$this->y -= 15;
$this->_setFontBold($page, 9.5);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawText(__('Payment Method :'), 300, $top + 40, 'UTF-8');
$page->drawText(__('Shipping Method :'), 300,$top + 25, 'UTF-8');
$this->y -= 10;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->_setFontRegular($page, 10);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$paymentLeft = 35;
$yPayments = $this->y - 15;
else
$yPayments = $addressesStartY;
$paymentLeft = 285;
foreach ($payment as $value)
if (trim($value) != '')
//Printing "Payment Method" lines
$value = preg_replace('/<br[^>]*>/i', "n", $value);
foreach ($this->string->split($value, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 400, $top + 40, 'UTF-8');
$yPayments -= 15;
if ($order->getIsVirtual())
// replacement of Shipments-Payments rectangle block
// $yPayments = min($addressesEndY, $yPayments);
// $page->drawLine(25, $top - 25, 25, $yPayments);
// $page->drawLine(570, $top - 25, 570, $yPayments);
// $page->drawLine(25, $yPayments, 570, $yPayments);
$this->y = $yPayments - 15;
else
$topMargin = 15;
$methodStartY = $this->y;
$this->y -= 15;
foreach ($this->string->split($shippingMethod, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 400, $top + 25, 'UTF-8');
$this->y -= 15;
$yShipments = $this->y;
$totalShippingChargesText = "(" . __(
'Total Shipping Charges'
) . " " . $order->formatPriceTxt(
$order->getShippingAmount()
) . ")";
$page->drawText($totalShippingChargesText, 400, $top + 12, 'UTF-8');
$yShipments -= $topMargin + 10;
$this->y -= -45;
Please Check my Result
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282456%2fhow-to-edit-invoice-pdf-in-magento-2-3%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Create custom module with below step.
step1 : di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice" type="AdamsmageTaxModelOrderPdfItemsInvoiceDefaultInvoice" />
<preference for="MagentoSalesModelOrderPdfInvoice" type="AdamsmageTaxModelOrderPdfInvoice" />
Step2 : copied the functions that i wanted to override of the abstract class in appcodeAdamsmageTaxModelOrderPdfInvoice.php
like one thing i wanted to change was fonts
/**
* 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() . ('dejavu-sans/DejaVuSansCondensed.ttf')
);
$object->setFont($font, $size);
return $font;
/**
* Set font as bold
*
* @param Zend_Pdf_Page $object
* @param int $size
* @return Zend_Pdf_Resource_Font
*/
protected function _setFontBold($object, $size = 6)
$font = Zend_Pdf_Font::fontWithPath(
$this->getFontsDir() . ('dejavu-sans/DejaVuSansCondensed-Bold.ttf')
);
$object->setFont($font, $size);
return $font;
/**
* Set font as italic
*
* @param Zend_Pdf_Page $object
* @param int $size
* @return Zend_Pdf_Resource_Font
*/
protected function _setFontItalic($object, $size = 7)
$font = Zend_Pdf_Font::fontWithPath(
$this->getFontsDir() . ('dejavu-sans/DejaVuSans-Oblique.ttf')
);
$object->setFont($font, $size);
return $font;
Step3 : modify to Insertorder
protected function insertOrder(&$page, $obj, $putOrderId = true)
if ($obj instanceof MagentoSalesModelOrder)
$shipment = null;
$order = $obj;
elseif ($obj instanceof MagentoSalesModelOrderShipment)
$shipment = $obj;
$order = $shipment->getOrder();
$sellerId=$order->getData('seller_id');
$sellerInfo=$this->_taxHelper->getSellerAdressWithDetails($sellerId);
$this->y = $this->y ? $this->y : 815;
$top = $this->y;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->drawRectangle(25, $top, 570, $top - 55);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->setDocHeaderCoordinates([25, $top, 570, $top - 55]);
$this->_setFontRegular($page, 10);
if ($putOrderId)
$page->drawText(__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8');
$page->drawText(
__('Order Date: ') .
$this->_localeDate->formatDate(
$this->_localeDate->scopeDate(
$order->getStore(),
$order->getCreatedAt(),
true
),
IntlDateFormatter::MEDIUM,
false
),
35,
$top -= 15,
'UTF-8'
);
$top -= 10;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 570, $top - 25);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold By:'), 35, $top - 15, 'UTF-8');
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - 80);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach(explode("n", $sellerInfo) as $textLine)
if ($textLine!=='')
$page->drawText(strip_tags(ltrim($textLine)), 35, $this->y, 'UTF-8');
$this->y -=14;
$addressesEndY = $this->y;
$top -= 120;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 275, $top - 25);
$page->drawRectangle(275, $top, 570, $top - 25);
/* Calculate blocks info */
/* Billing Address */
$billingAddress = $this->_formatAddress($this->addressRenderer->format($order->getBillingAddress(), 'pdf'));
/* Payment */
$paymentInfo = $this->_paymentData->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf();
$paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
$payment = explode('pdf_row_separator', $paymentInfo);
foreach ($payment as $key => $value)
if (strip_tags(trim($value)) == '')
unset($payment[$key]);
reset($payment);
/* Shipping Address and Method */
if (!$order->getIsVirtual())
/* Shipping Address */
$shippingAddress = $this->_formatAddress($this->addressRenderer->format($order->getShippingAddress(), 'pdf'));
$shippingMethod = $order->getShippingDescription();
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold to:'), 35, $top - 15, 'UTF-8');
if (!$order->getIsVirtual())
$page->drawText(__('Ship to:'), 285, $top - 15, 'UTF-8');
else
$page->drawText(__('Payment Method:'), 285, $top - 15, 'UTF-8');
$addressesHeight = $this->_calcAddressHeight($billingAddress);
if (isset($shippingAddress))
$addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress));
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - $addressesHeight);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach ($billingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 45, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = $this->y;
if (!$order->getIsVirtual())
$this->y = $addressesStartY;
foreach ($shippingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 45, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = min($addressesEndY, $this->y);
$this->y = $addressesEndY;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $this->y, 275, $this->y - 25);
$page->drawRectangle(275, $this->y, 570, $this->y - 25);
$this->y -= 15;
$this->_setFontBold($page, 12);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$page->drawText(__('Payment Method'), 35, $this->y, 'UTF-8');
$page->drawText(__('Shipping Method:'), 285, $this->y, 'UTF-8');
$this->y -= 10;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->_setFontRegular($page, 10);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$paymentLeft = 35;
$yPayments = $this->y - 15;
else
$yPayments = $addressesStartY;
$paymentLeft = 285;
foreach ($payment as $value)
if (trim($value) != '')
//Printing "Payment comments" lines
$value = preg_replace('/<br[^>]*>/i', "n", $value);
foreach ($this->string->split($value, 45, true, true) as $_value)
if($_value=='No value')
$_value='No pay';
$page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8');
$yPayments -= 15;
if ($order->getIsVirtual())
// replacement of Shipments-Payments rectangle block
$yPayments = min($addressesEndY, $yPayments);
$page->drawLine(25, $top - 25, 25, $yPayments);
$page->drawLine(570, $top - 25, 570, $yPayments);
$page->drawLine(25, $yPayments, 570, $yPayments);
$this->y = $yPayments - 15;
else
$topMargin = 15;
$methodStartY = $this->y;
$this->y -= 15;
foreach ($this->string->split($shippingMethod, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$yShipments = $this->y;
$totalShippingChargesText = "(" . __(
'Total Shipping Charges'
) . " " . $order->formatPriceTxt(
$order->getShippingAmount()
) . ")";
$page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8');
$yShipments -= $topMargin + 10;
$tracks = [];
if ($shipment)
$tracks = $shipment->getAllTracks();
if (count($tracks))
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineWidth(0.5);
$page->drawRectangle(285, $yShipments, 510, $yShipments - 10);
$page->drawLine(400, $yShipments, 400, $yShipments - 10);
//$page->drawLine(510, $yShipments, 510, $yShipments - 10);
$this->_setFontRegular($page, 9);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
//$page->drawText(__('Carrier'), 290, $yShipments - 7 , 'UTF-8');
$page->drawText(__('Title'), 290, $yShipments - 7, 'UTF-8');
$page->drawText(__('Number'), 410, $yShipments - 7, 'UTF-8');
$yShipments -= 20;
$this->_setFontRegular($page, 8);
foreach ($tracks as $track)
$maxTitleLen = 45;
$endOfTitle = strlen($track->getTitle()) > $maxTitleLen ? '...' : '';
$truncatedTitle = substr($track->getTitle(), 0, $maxTitleLen) . $endOfTitle;
$page->drawText($truncatedTitle, 292, $yShipments, 'UTF-8');
$page->drawText($track->getNumber(), 410, $yShipments, 'UTF-8');
$yShipments -= $topMargin - 5;
else
$yShipments -= $topMargin - 5;
$currentY = min($yPayments, $yShipments);
// replacement of Shipments-Payments rectangle block
$page->drawLine(25, $methodStartY, 25, $currentY);
//left
$page->drawLine(25, $currentY, 570, $currentY);
//bottom
$page->drawLine(570, $currentY, 570, $methodStartY);
//right
$this->y = $currentY;
$this->y -= 15;
if you want to change another than check with below file.app/code/Magento/Sales/Model/Order/Pdf/Invoice.php
or vendor/magento/module-sales/Model/Order/Pdf/Invoice.php
Thank you fir your replay
– Shafeel Sha
Jul 18 at 6:05
Undefined property: ModelOrderPdfInvoice::$_taxHelper in /Model/Order/Pdf/Invoice.php on line 618 , error appears
– Shafeel Sha
Jul 18 at 6:05
try with clear cache and other basic commands. if than not working then please add code inside construct public function __construct(MagentoCatalogHelperData $taxHelper) $this->_taxHelper = $taxHelper;
– Anas Mansuri
Jul 18 at 6:14
add a comment |
Create custom module with below step.
step1 : di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice" type="AdamsmageTaxModelOrderPdfItemsInvoiceDefaultInvoice" />
<preference for="MagentoSalesModelOrderPdfInvoice" type="AdamsmageTaxModelOrderPdfInvoice" />
Step2 : copied the functions that i wanted to override of the abstract class in appcodeAdamsmageTaxModelOrderPdfInvoice.php
like one thing i wanted to change was fonts
/**
* 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() . ('dejavu-sans/DejaVuSansCondensed.ttf')
);
$object->setFont($font, $size);
return $font;
/**
* Set font as bold
*
* @param Zend_Pdf_Page $object
* @param int $size
* @return Zend_Pdf_Resource_Font
*/
protected function _setFontBold($object, $size = 6)
$font = Zend_Pdf_Font::fontWithPath(
$this->getFontsDir() . ('dejavu-sans/DejaVuSansCondensed-Bold.ttf')
);
$object->setFont($font, $size);
return $font;
/**
* Set font as italic
*
* @param Zend_Pdf_Page $object
* @param int $size
* @return Zend_Pdf_Resource_Font
*/
protected function _setFontItalic($object, $size = 7)
$font = Zend_Pdf_Font::fontWithPath(
$this->getFontsDir() . ('dejavu-sans/DejaVuSans-Oblique.ttf')
);
$object->setFont($font, $size);
return $font;
Step3 : modify to Insertorder
protected function insertOrder(&$page, $obj, $putOrderId = true)
if ($obj instanceof MagentoSalesModelOrder)
$shipment = null;
$order = $obj;
elseif ($obj instanceof MagentoSalesModelOrderShipment)
$shipment = $obj;
$order = $shipment->getOrder();
$sellerId=$order->getData('seller_id');
$sellerInfo=$this->_taxHelper->getSellerAdressWithDetails($sellerId);
$this->y = $this->y ? $this->y : 815;
$top = $this->y;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->drawRectangle(25, $top, 570, $top - 55);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->setDocHeaderCoordinates([25, $top, 570, $top - 55]);
$this->_setFontRegular($page, 10);
if ($putOrderId)
$page->drawText(__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8');
$page->drawText(
__('Order Date: ') .
$this->_localeDate->formatDate(
$this->_localeDate->scopeDate(
$order->getStore(),
$order->getCreatedAt(),
true
),
IntlDateFormatter::MEDIUM,
false
),
35,
$top -= 15,
'UTF-8'
);
$top -= 10;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 570, $top - 25);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold By:'), 35, $top - 15, 'UTF-8');
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - 80);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach(explode("n", $sellerInfo) as $textLine)
if ($textLine!=='')
$page->drawText(strip_tags(ltrim($textLine)), 35, $this->y, 'UTF-8');
$this->y -=14;
$addressesEndY = $this->y;
$top -= 120;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 275, $top - 25);
$page->drawRectangle(275, $top, 570, $top - 25);
/* Calculate blocks info */
/* Billing Address */
$billingAddress = $this->_formatAddress($this->addressRenderer->format($order->getBillingAddress(), 'pdf'));
/* Payment */
$paymentInfo = $this->_paymentData->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf();
$paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
$payment = explode('pdf_row_separator', $paymentInfo);
foreach ($payment as $key => $value)
if (strip_tags(trim($value)) == '')
unset($payment[$key]);
reset($payment);
/* Shipping Address and Method */
if (!$order->getIsVirtual())
/* Shipping Address */
$shippingAddress = $this->_formatAddress($this->addressRenderer->format($order->getShippingAddress(), 'pdf'));
$shippingMethod = $order->getShippingDescription();
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold to:'), 35, $top - 15, 'UTF-8');
if (!$order->getIsVirtual())
$page->drawText(__('Ship to:'), 285, $top - 15, 'UTF-8');
else
$page->drawText(__('Payment Method:'), 285, $top - 15, 'UTF-8');
$addressesHeight = $this->_calcAddressHeight($billingAddress);
if (isset($shippingAddress))
$addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress));
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - $addressesHeight);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach ($billingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 45, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = $this->y;
if (!$order->getIsVirtual())
$this->y = $addressesStartY;
foreach ($shippingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 45, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = min($addressesEndY, $this->y);
$this->y = $addressesEndY;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $this->y, 275, $this->y - 25);
$page->drawRectangle(275, $this->y, 570, $this->y - 25);
$this->y -= 15;
$this->_setFontBold($page, 12);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$page->drawText(__('Payment Method'), 35, $this->y, 'UTF-8');
$page->drawText(__('Shipping Method:'), 285, $this->y, 'UTF-8');
$this->y -= 10;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->_setFontRegular($page, 10);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$paymentLeft = 35;
$yPayments = $this->y - 15;
else
$yPayments = $addressesStartY;
$paymentLeft = 285;
foreach ($payment as $value)
if (trim($value) != '')
//Printing "Payment comments" lines
$value = preg_replace('/<br[^>]*>/i', "n", $value);
foreach ($this->string->split($value, 45, true, true) as $_value)
if($_value=='No value')
$_value='No pay';
$page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8');
$yPayments -= 15;
if ($order->getIsVirtual())
// replacement of Shipments-Payments rectangle block
$yPayments = min($addressesEndY, $yPayments);
$page->drawLine(25, $top - 25, 25, $yPayments);
$page->drawLine(570, $top - 25, 570, $yPayments);
$page->drawLine(25, $yPayments, 570, $yPayments);
$this->y = $yPayments - 15;
else
$topMargin = 15;
$methodStartY = $this->y;
$this->y -= 15;
foreach ($this->string->split($shippingMethod, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$yShipments = $this->y;
$totalShippingChargesText = "(" . __(
'Total Shipping Charges'
) . " " . $order->formatPriceTxt(
$order->getShippingAmount()
) . ")";
$page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8');
$yShipments -= $topMargin + 10;
$tracks = [];
if ($shipment)
$tracks = $shipment->getAllTracks();
if (count($tracks))
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineWidth(0.5);
$page->drawRectangle(285, $yShipments, 510, $yShipments - 10);
$page->drawLine(400, $yShipments, 400, $yShipments - 10);
//$page->drawLine(510, $yShipments, 510, $yShipments - 10);
$this->_setFontRegular($page, 9);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
//$page->drawText(__('Carrier'), 290, $yShipments - 7 , 'UTF-8');
$page->drawText(__('Title'), 290, $yShipments - 7, 'UTF-8');
$page->drawText(__('Number'), 410, $yShipments - 7, 'UTF-8');
$yShipments -= 20;
$this->_setFontRegular($page, 8);
foreach ($tracks as $track)
$maxTitleLen = 45;
$endOfTitle = strlen($track->getTitle()) > $maxTitleLen ? '...' : '';
$truncatedTitle = substr($track->getTitle(), 0, $maxTitleLen) . $endOfTitle;
$page->drawText($truncatedTitle, 292, $yShipments, 'UTF-8');
$page->drawText($track->getNumber(), 410, $yShipments, 'UTF-8');
$yShipments -= $topMargin - 5;
else
$yShipments -= $topMargin - 5;
$currentY = min($yPayments, $yShipments);
// replacement of Shipments-Payments rectangle block
$page->drawLine(25, $methodStartY, 25, $currentY);
//left
$page->drawLine(25, $currentY, 570, $currentY);
//bottom
$page->drawLine(570, $currentY, 570, $methodStartY);
//right
$this->y = $currentY;
$this->y -= 15;
if you want to change another than check with below file.app/code/Magento/Sales/Model/Order/Pdf/Invoice.php
or vendor/magento/module-sales/Model/Order/Pdf/Invoice.php
Thank you fir your replay
– Shafeel Sha
Jul 18 at 6:05
Undefined property: ModelOrderPdfInvoice::$_taxHelper in /Model/Order/Pdf/Invoice.php on line 618 , error appears
– Shafeel Sha
Jul 18 at 6:05
try with clear cache and other basic commands. if than not working then please add code inside construct public function __construct(MagentoCatalogHelperData $taxHelper) $this->_taxHelper = $taxHelper;
– Anas Mansuri
Jul 18 at 6:14
add a comment |
Create custom module with below step.
step1 : di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice" type="AdamsmageTaxModelOrderPdfItemsInvoiceDefaultInvoice" />
<preference for="MagentoSalesModelOrderPdfInvoice" type="AdamsmageTaxModelOrderPdfInvoice" />
Step2 : copied the functions that i wanted to override of the abstract class in appcodeAdamsmageTaxModelOrderPdfInvoice.php
like one thing i wanted to change was fonts
/**
* 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() . ('dejavu-sans/DejaVuSansCondensed.ttf')
);
$object->setFont($font, $size);
return $font;
/**
* Set font as bold
*
* @param Zend_Pdf_Page $object
* @param int $size
* @return Zend_Pdf_Resource_Font
*/
protected function _setFontBold($object, $size = 6)
$font = Zend_Pdf_Font::fontWithPath(
$this->getFontsDir() . ('dejavu-sans/DejaVuSansCondensed-Bold.ttf')
);
$object->setFont($font, $size);
return $font;
/**
* Set font as italic
*
* @param Zend_Pdf_Page $object
* @param int $size
* @return Zend_Pdf_Resource_Font
*/
protected function _setFontItalic($object, $size = 7)
$font = Zend_Pdf_Font::fontWithPath(
$this->getFontsDir() . ('dejavu-sans/DejaVuSans-Oblique.ttf')
);
$object->setFont($font, $size);
return $font;
Step3 : modify to Insertorder
protected function insertOrder(&$page, $obj, $putOrderId = true)
if ($obj instanceof MagentoSalesModelOrder)
$shipment = null;
$order = $obj;
elseif ($obj instanceof MagentoSalesModelOrderShipment)
$shipment = $obj;
$order = $shipment->getOrder();
$sellerId=$order->getData('seller_id');
$sellerInfo=$this->_taxHelper->getSellerAdressWithDetails($sellerId);
$this->y = $this->y ? $this->y : 815;
$top = $this->y;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->drawRectangle(25, $top, 570, $top - 55);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->setDocHeaderCoordinates([25, $top, 570, $top - 55]);
$this->_setFontRegular($page, 10);
if ($putOrderId)
$page->drawText(__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8');
$page->drawText(
__('Order Date: ') .
$this->_localeDate->formatDate(
$this->_localeDate->scopeDate(
$order->getStore(),
$order->getCreatedAt(),
true
),
IntlDateFormatter::MEDIUM,
false
),
35,
$top -= 15,
'UTF-8'
);
$top -= 10;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 570, $top - 25);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold By:'), 35, $top - 15, 'UTF-8');
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - 80);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach(explode("n", $sellerInfo) as $textLine)
if ($textLine!=='')
$page->drawText(strip_tags(ltrim($textLine)), 35, $this->y, 'UTF-8');
$this->y -=14;
$addressesEndY = $this->y;
$top -= 120;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 275, $top - 25);
$page->drawRectangle(275, $top, 570, $top - 25);
/* Calculate blocks info */
/* Billing Address */
$billingAddress = $this->_formatAddress($this->addressRenderer->format($order->getBillingAddress(), 'pdf'));
/* Payment */
$paymentInfo = $this->_paymentData->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf();
$paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
$payment = explode('pdf_row_separator', $paymentInfo);
foreach ($payment as $key => $value)
if (strip_tags(trim($value)) == '')
unset($payment[$key]);
reset($payment);
/* Shipping Address and Method */
if (!$order->getIsVirtual())
/* Shipping Address */
$shippingAddress = $this->_formatAddress($this->addressRenderer->format($order->getShippingAddress(), 'pdf'));
$shippingMethod = $order->getShippingDescription();
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold to:'), 35, $top - 15, 'UTF-8');
if (!$order->getIsVirtual())
$page->drawText(__('Ship to:'), 285, $top - 15, 'UTF-8');
else
$page->drawText(__('Payment Method:'), 285, $top - 15, 'UTF-8');
$addressesHeight = $this->_calcAddressHeight($billingAddress);
if (isset($shippingAddress))
$addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress));
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - $addressesHeight);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach ($billingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 45, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = $this->y;
if (!$order->getIsVirtual())
$this->y = $addressesStartY;
foreach ($shippingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 45, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = min($addressesEndY, $this->y);
$this->y = $addressesEndY;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $this->y, 275, $this->y - 25);
$page->drawRectangle(275, $this->y, 570, $this->y - 25);
$this->y -= 15;
$this->_setFontBold($page, 12);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$page->drawText(__('Payment Method'), 35, $this->y, 'UTF-8');
$page->drawText(__('Shipping Method:'), 285, $this->y, 'UTF-8');
$this->y -= 10;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->_setFontRegular($page, 10);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$paymentLeft = 35;
$yPayments = $this->y - 15;
else
$yPayments = $addressesStartY;
$paymentLeft = 285;
foreach ($payment as $value)
if (trim($value) != '')
//Printing "Payment comments" lines
$value = preg_replace('/<br[^>]*>/i', "n", $value);
foreach ($this->string->split($value, 45, true, true) as $_value)
if($_value=='No value')
$_value='No pay';
$page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8');
$yPayments -= 15;
if ($order->getIsVirtual())
// replacement of Shipments-Payments rectangle block
$yPayments = min($addressesEndY, $yPayments);
$page->drawLine(25, $top - 25, 25, $yPayments);
$page->drawLine(570, $top - 25, 570, $yPayments);
$page->drawLine(25, $yPayments, 570, $yPayments);
$this->y = $yPayments - 15;
else
$topMargin = 15;
$methodStartY = $this->y;
$this->y -= 15;
foreach ($this->string->split($shippingMethod, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$yShipments = $this->y;
$totalShippingChargesText = "(" . __(
'Total Shipping Charges'
) . " " . $order->formatPriceTxt(
$order->getShippingAmount()
) . ")";
$page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8');
$yShipments -= $topMargin + 10;
$tracks = [];
if ($shipment)
$tracks = $shipment->getAllTracks();
if (count($tracks))
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineWidth(0.5);
$page->drawRectangle(285, $yShipments, 510, $yShipments - 10);
$page->drawLine(400, $yShipments, 400, $yShipments - 10);
//$page->drawLine(510, $yShipments, 510, $yShipments - 10);
$this->_setFontRegular($page, 9);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
//$page->drawText(__('Carrier'), 290, $yShipments - 7 , 'UTF-8');
$page->drawText(__('Title'), 290, $yShipments - 7, 'UTF-8');
$page->drawText(__('Number'), 410, $yShipments - 7, 'UTF-8');
$yShipments -= 20;
$this->_setFontRegular($page, 8);
foreach ($tracks as $track)
$maxTitleLen = 45;
$endOfTitle = strlen($track->getTitle()) > $maxTitleLen ? '...' : '';
$truncatedTitle = substr($track->getTitle(), 0, $maxTitleLen) . $endOfTitle;
$page->drawText($truncatedTitle, 292, $yShipments, 'UTF-8');
$page->drawText($track->getNumber(), 410, $yShipments, 'UTF-8');
$yShipments -= $topMargin - 5;
else
$yShipments -= $topMargin - 5;
$currentY = min($yPayments, $yShipments);
// replacement of Shipments-Payments rectangle block
$page->drawLine(25, $methodStartY, 25, $currentY);
//left
$page->drawLine(25, $currentY, 570, $currentY);
//bottom
$page->drawLine(570, $currentY, 570, $methodStartY);
//right
$this->y = $currentY;
$this->y -= 15;
if you want to change another than check with below file.app/code/Magento/Sales/Model/Order/Pdf/Invoice.php
or vendor/magento/module-sales/Model/Order/Pdf/Invoice.php
Create custom module with below step.
step1 : di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice" type="AdamsmageTaxModelOrderPdfItemsInvoiceDefaultInvoice" />
<preference for="MagentoSalesModelOrderPdfInvoice" type="AdamsmageTaxModelOrderPdfInvoice" />
Step2 : copied the functions that i wanted to override of the abstract class in appcodeAdamsmageTaxModelOrderPdfInvoice.php
like one thing i wanted to change was fonts
/**
* 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() . ('dejavu-sans/DejaVuSansCondensed.ttf')
);
$object->setFont($font, $size);
return $font;
/**
* Set font as bold
*
* @param Zend_Pdf_Page $object
* @param int $size
* @return Zend_Pdf_Resource_Font
*/
protected function _setFontBold($object, $size = 6)
$font = Zend_Pdf_Font::fontWithPath(
$this->getFontsDir() . ('dejavu-sans/DejaVuSansCondensed-Bold.ttf')
);
$object->setFont($font, $size);
return $font;
/**
* Set font as italic
*
* @param Zend_Pdf_Page $object
* @param int $size
* @return Zend_Pdf_Resource_Font
*/
protected function _setFontItalic($object, $size = 7)
$font = Zend_Pdf_Font::fontWithPath(
$this->getFontsDir() . ('dejavu-sans/DejaVuSans-Oblique.ttf')
);
$object->setFont($font, $size);
return $font;
Step3 : modify to Insertorder
protected function insertOrder(&$page, $obj, $putOrderId = true)
if ($obj instanceof MagentoSalesModelOrder)
$shipment = null;
$order = $obj;
elseif ($obj instanceof MagentoSalesModelOrderShipment)
$shipment = $obj;
$order = $shipment->getOrder();
$sellerId=$order->getData('seller_id');
$sellerInfo=$this->_taxHelper->getSellerAdressWithDetails($sellerId);
$this->y = $this->y ? $this->y : 815;
$top = $this->y;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->drawRectangle(25, $top, 570, $top - 55);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->setDocHeaderCoordinates([25, $top, 570, $top - 55]);
$this->_setFontRegular($page, 10);
if ($putOrderId)
$page->drawText(__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8');
$page->drawText(
__('Order Date: ') .
$this->_localeDate->formatDate(
$this->_localeDate->scopeDate(
$order->getStore(),
$order->getCreatedAt(),
true
),
IntlDateFormatter::MEDIUM,
false
),
35,
$top -= 15,
'UTF-8'
);
$top -= 10;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 570, $top - 25);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold By:'), 35, $top - 15, 'UTF-8');
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - 80);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach(explode("n", $sellerInfo) as $textLine)
if ($textLine!=='')
$page->drawText(strip_tags(ltrim($textLine)), 35, $this->y, 'UTF-8');
$this->y -=14;
$addressesEndY = $this->y;
$top -= 120;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 275, $top - 25);
$page->drawRectangle(275, $top, 570, $top - 25);
/* Calculate blocks info */
/* Billing Address */
$billingAddress = $this->_formatAddress($this->addressRenderer->format($order->getBillingAddress(), 'pdf'));
/* Payment */
$paymentInfo = $this->_paymentData->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf();
$paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
$payment = explode('pdf_row_separator', $paymentInfo);
foreach ($payment as $key => $value)
if (strip_tags(trim($value)) == '')
unset($payment[$key]);
reset($payment);
/* Shipping Address and Method */
if (!$order->getIsVirtual())
/* Shipping Address */
$shippingAddress = $this->_formatAddress($this->addressRenderer->format($order->getShippingAddress(), 'pdf'));
$shippingMethod = $order->getShippingDescription();
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold to:'), 35, $top - 15, 'UTF-8');
if (!$order->getIsVirtual())
$page->drawText(__('Ship to:'), 285, $top - 15, 'UTF-8');
else
$page->drawText(__('Payment Method:'), 285, $top - 15, 'UTF-8');
$addressesHeight = $this->_calcAddressHeight($billingAddress);
if (isset($shippingAddress))
$addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress));
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - $addressesHeight);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach ($billingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 45, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = $this->y;
if (!$order->getIsVirtual())
$this->y = $addressesStartY;
foreach ($shippingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 45, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = min($addressesEndY, $this->y);
$this->y = $addressesEndY;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $this->y, 275, $this->y - 25);
$page->drawRectangle(275, $this->y, 570, $this->y - 25);
$this->y -= 15;
$this->_setFontBold($page, 12);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$page->drawText(__('Payment Method'), 35, $this->y, 'UTF-8');
$page->drawText(__('Shipping Method:'), 285, $this->y, 'UTF-8');
$this->y -= 10;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->_setFontRegular($page, 10);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$paymentLeft = 35;
$yPayments = $this->y - 15;
else
$yPayments = $addressesStartY;
$paymentLeft = 285;
foreach ($payment as $value)
if (trim($value) != '')
//Printing "Payment comments" lines
$value = preg_replace('/<br[^>]*>/i', "n", $value);
foreach ($this->string->split($value, 45, true, true) as $_value)
if($_value=='No value')
$_value='No pay';
$page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8');
$yPayments -= 15;
if ($order->getIsVirtual())
// replacement of Shipments-Payments rectangle block
$yPayments = min($addressesEndY, $yPayments);
$page->drawLine(25, $top - 25, 25, $yPayments);
$page->drawLine(570, $top - 25, 570, $yPayments);
$page->drawLine(25, $yPayments, 570, $yPayments);
$this->y = $yPayments - 15;
else
$topMargin = 15;
$methodStartY = $this->y;
$this->y -= 15;
foreach ($this->string->split($shippingMethod, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$yShipments = $this->y;
$totalShippingChargesText = "(" . __(
'Total Shipping Charges'
) . " " . $order->formatPriceTxt(
$order->getShippingAmount()
) . ")";
$page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8');
$yShipments -= $topMargin + 10;
$tracks = [];
if ($shipment)
$tracks = $shipment->getAllTracks();
if (count($tracks))
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineWidth(0.5);
$page->drawRectangle(285, $yShipments, 510, $yShipments - 10);
$page->drawLine(400, $yShipments, 400, $yShipments - 10);
//$page->drawLine(510, $yShipments, 510, $yShipments - 10);
$this->_setFontRegular($page, 9);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
//$page->drawText(__('Carrier'), 290, $yShipments - 7 , 'UTF-8');
$page->drawText(__('Title'), 290, $yShipments - 7, 'UTF-8');
$page->drawText(__('Number'), 410, $yShipments - 7, 'UTF-8');
$yShipments -= 20;
$this->_setFontRegular($page, 8);
foreach ($tracks as $track)
$maxTitleLen = 45;
$endOfTitle = strlen($track->getTitle()) > $maxTitleLen ? '...' : '';
$truncatedTitle = substr($track->getTitle(), 0, $maxTitleLen) . $endOfTitle;
$page->drawText($truncatedTitle, 292, $yShipments, 'UTF-8');
$page->drawText($track->getNumber(), 410, $yShipments, 'UTF-8');
$yShipments -= $topMargin - 5;
else
$yShipments -= $topMargin - 5;
$currentY = min($yPayments, $yShipments);
// replacement of Shipments-Payments rectangle block
$page->drawLine(25, $methodStartY, 25, $currentY);
//left
$page->drawLine(25, $currentY, 570, $currentY);
//bottom
$page->drawLine(570, $currentY, 570, $methodStartY);
//right
$this->y = $currentY;
$this->y -= 15;
if you want to change another than check with below file.app/code/Magento/Sales/Model/Order/Pdf/Invoice.php
or vendor/magento/module-sales/Model/Order/Pdf/Invoice.php
answered Jul 18 at 5:30
Anas MansuriAnas Mansuri
1,1271 silver badge16 bronze badges
1,1271 silver badge16 bronze badges
Thank you fir your replay
– Shafeel Sha
Jul 18 at 6:05
Undefined property: ModelOrderPdfInvoice::$_taxHelper in /Model/Order/Pdf/Invoice.php on line 618 , error appears
– Shafeel Sha
Jul 18 at 6:05
try with clear cache and other basic commands. if than not working then please add code inside construct public function __construct(MagentoCatalogHelperData $taxHelper) $this->_taxHelper = $taxHelper;
– Anas Mansuri
Jul 18 at 6:14
add a comment |
Thank you fir your replay
– Shafeel Sha
Jul 18 at 6:05
Undefined property: ModelOrderPdfInvoice::$_taxHelper in /Model/Order/Pdf/Invoice.php on line 618 , error appears
– Shafeel Sha
Jul 18 at 6:05
try with clear cache and other basic commands. if than not working then please add code inside construct public function __construct(MagentoCatalogHelperData $taxHelper) $this->_taxHelper = $taxHelper;
– Anas Mansuri
Jul 18 at 6:14
Thank you fir your replay
– Shafeel Sha
Jul 18 at 6:05
Thank you fir your replay
– Shafeel Sha
Jul 18 at 6:05
Undefined property: ModelOrderPdfInvoice::$_taxHelper in /Model/Order/Pdf/Invoice.php on line 618 , error appears
– Shafeel Sha
Jul 18 at 6:05
Undefined property: ModelOrderPdfInvoice::$_taxHelper in /Model/Order/Pdf/Invoice.php on line 618 , error appears
– Shafeel Sha
Jul 18 at 6:05
try with clear cache and other basic commands. if than not working then please add code inside construct public function __construct(MagentoCatalogHelperData $taxHelper) $this->_taxHelper = $taxHelper;
– Anas Mansuri
Jul 18 at 6:14
try with clear cache and other basic commands. if than not working then please add code inside construct public function __construct(MagentoCatalogHelperData $taxHelper) $this->_taxHelper = $taxHelper;
– Anas Mansuri
Jul 18 at 6:14
add a comment |
override of the abstract class in
appcodeVendorModuleModelOrderPdfInvoice.php
In my case i'm hide that 'red boarded table and update below function insertOrderCustom and adjust element positions via changing $top variable values also comment drawLine codes ,if you need customize below coses basis on your requirement.
protected function insertOrderCustom(&$page, $obj, $putOrderId = true)
if ($obj instanceof MagentoSalesModelOrder)
$shipment = null;
$order = $obj;
elseif ($obj instanceof MagentoSalesModelOrderShipment)
$shipment = $obj;
$order = $shipment->getOrder();
$this->y = $this->y ? $this->y : 815;
$top = $this->y;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->drawRectangle(25, $top, 570, $top - 65);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->setDocHeaderCoordinates([25, $top, 570, $top - 55]);
$this->_setFontRegular($page, 10);
if ($putOrderId)
$page->drawText(__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8');
$page->drawText(
__('Order Date: ') .
$this->_localeDate->formatDate(
$this->_localeDate->scopeDate(
$order->getStore(),
$order->getCreatedAt(),
true
),
IntlDateFormatter::MEDIUM,
false
),
35,
$top -= 15,
'UTF-8'
);
$gstin = $this->_scopeConfig->getValue(
"gst/codilar/gstin",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
if (strlen($gstin)>0)
//$page->drawText(__('GSTIN : ') . $gstin, 35, $top -= 15, 'UTF-8');
$top -= 10;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 275, $top - 25);
$page->drawRectangle(275, $top, 570, $top - 25);
/* Calculate blocks info */
/* Billing Address */
$billingAddress = $this->_formatAddress($this->addressRenderer->format($order->getBillingAddress(), 'pdf'));
$gstin = 'GSTIN: '.$order->getBillingAddress()->getData('gstin');
if($gstin != null)
array_push($billingAddress,$gstin);
/* Payment */
$paymentInfo = $this->_paymentData->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf();
$paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
$payment = explode('pdf_row_separator', $paymentInfo);
foreach ($payment as $key => $value)
if (strip_tags(trim($value)) == '')
unset($payment[$key]);
reset($payment);
/* Shipping Address and Method */
if (!$order->getIsVirtual())
/* Shipping Address */
$shippingAddress = $this->_formatAddress($this->addressRenderer->format($order->getShippingAddress(), 'pdf'));
$shippingMethod = $order->getShippingDescription();
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold to:'), 35, $top - 15, 'UTF-8');
if (!$order->getIsVirtual())
$page->drawText(__('Ship to:'), 285, $top - 15, 'UTF-8');
else
$page->drawText(__('Payment Method:'), 285, $top - 15, 'UTF-8');
$addressesHeight = $this->_calcAddressHeight($billingAddress);
if (isset($shippingAddress))
$addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress));
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - $addressesHeight);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach ($billingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 40, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = $this->y;
if (!$order->getIsVirtual())
$this->y = $addressesStartY;
foreach ($shippingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 40, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = min($addressesEndY, $this->y);
$this->y = $addressesEndY;
$this->y -= 15;
$this->_setFontBold($page, 9.5);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawText(__('Payment Method :'), 300, $top + 40, 'UTF-8');
$page->drawText(__('Shipping Method :'), 300,$top + 25, 'UTF-8');
$this->y -= 10;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->_setFontRegular($page, 10);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$paymentLeft = 35;
$yPayments = $this->y - 15;
else
$yPayments = $addressesStartY;
$paymentLeft = 285;
foreach ($payment as $value)
if (trim($value) != '')
//Printing "Payment Method" lines
$value = preg_replace('/<br[^>]*>/i', "n", $value);
foreach ($this->string->split($value, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 400, $top + 40, 'UTF-8');
$yPayments -= 15;
if ($order->getIsVirtual())
// replacement of Shipments-Payments rectangle block
// $yPayments = min($addressesEndY, $yPayments);
// $page->drawLine(25, $top - 25, 25, $yPayments);
// $page->drawLine(570, $top - 25, 570, $yPayments);
// $page->drawLine(25, $yPayments, 570, $yPayments);
$this->y = $yPayments - 15;
else
$topMargin = 15;
$methodStartY = $this->y;
$this->y -= 15;
foreach ($this->string->split($shippingMethod, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 400, $top + 25, 'UTF-8');
$this->y -= 15;
$yShipments = $this->y;
$totalShippingChargesText = "(" . __(
'Total Shipping Charges'
) . " " . $order->formatPriceTxt(
$order->getShippingAmount()
) . ")";
$page->drawText($totalShippingChargesText, 400, $top + 12, 'UTF-8');
$yShipments -= $topMargin + 10;
$this->y -= -45;
Please Check my Result
add a comment |
override of the abstract class in
appcodeVendorModuleModelOrderPdfInvoice.php
In my case i'm hide that 'red boarded table and update below function insertOrderCustom and adjust element positions via changing $top variable values also comment drawLine codes ,if you need customize below coses basis on your requirement.
protected function insertOrderCustom(&$page, $obj, $putOrderId = true)
if ($obj instanceof MagentoSalesModelOrder)
$shipment = null;
$order = $obj;
elseif ($obj instanceof MagentoSalesModelOrderShipment)
$shipment = $obj;
$order = $shipment->getOrder();
$this->y = $this->y ? $this->y : 815;
$top = $this->y;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->drawRectangle(25, $top, 570, $top - 65);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->setDocHeaderCoordinates([25, $top, 570, $top - 55]);
$this->_setFontRegular($page, 10);
if ($putOrderId)
$page->drawText(__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8');
$page->drawText(
__('Order Date: ') .
$this->_localeDate->formatDate(
$this->_localeDate->scopeDate(
$order->getStore(),
$order->getCreatedAt(),
true
),
IntlDateFormatter::MEDIUM,
false
),
35,
$top -= 15,
'UTF-8'
);
$gstin = $this->_scopeConfig->getValue(
"gst/codilar/gstin",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
if (strlen($gstin)>0)
//$page->drawText(__('GSTIN : ') . $gstin, 35, $top -= 15, 'UTF-8');
$top -= 10;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 275, $top - 25);
$page->drawRectangle(275, $top, 570, $top - 25);
/* Calculate blocks info */
/* Billing Address */
$billingAddress = $this->_formatAddress($this->addressRenderer->format($order->getBillingAddress(), 'pdf'));
$gstin = 'GSTIN: '.$order->getBillingAddress()->getData('gstin');
if($gstin != null)
array_push($billingAddress,$gstin);
/* Payment */
$paymentInfo = $this->_paymentData->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf();
$paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
$payment = explode('pdf_row_separator', $paymentInfo);
foreach ($payment as $key => $value)
if (strip_tags(trim($value)) == '')
unset($payment[$key]);
reset($payment);
/* Shipping Address and Method */
if (!$order->getIsVirtual())
/* Shipping Address */
$shippingAddress = $this->_formatAddress($this->addressRenderer->format($order->getShippingAddress(), 'pdf'));
$shippingMethod = $order->getShippingDescription();
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold to:'), 35, $top - 15, 'UTF-8');
if (!$order->getIsVirtual())
$page->drawText(__('Ship to:'), 285, $top - 15, 'UTF-8');
else
$page->drawText(__('Payment Method:'), 285, $top - 15, 'UTF-8');
$addressesHeight = $this->_calcAddressHeight($billingAddress);
if (isset($shippingAddress))
$addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress));
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - $addressesHeight);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach ($billingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 40, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = $this->y;
if (!$order->getIsVirtual())
$this->y = $addressesStartY;
foreach ($shippingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 40, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = min($addressesEndY, $this->y);
$this->y = $addressesEndY;
$this->y -= 15;
$this->_setFontBold($page, 9.5);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawText(__('Payment Method :'), 300, $top + 40, 'UTF-8');
$page->drawText(__('Shipping Method :'), 300,$top + 25, 'UTF-8');
$this->y -= 10;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->_setFontRegular($page, 10);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$paymentLeft = 35;
$yPayments = $this->y - 15;
else
$yPayments = $addressesStartY;
$paymentLeft = 285;
foreach ($payment as $value)
if (trim($value) != '')
//Printing "Payment Method" lines
$value = preg_replace('/<br[^>]*>/i', "n", $value);
foreach ($this->string->split($value, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 400, $top + 40, 'UTF-8');
$yPayments -= 15;
if ($order->getIsVirtual())
// replacement of Shipments-Payments rectangle block
// $yPayments = min($addressesEndY, $yPayments);
// $page->drawLine(25, $top - 25, 25, $yPayments);
// $page->drawLine(570, $top - 25, 570, $yPayments);
// $page->drawLine(25, $yPayments, 570, $yPayments);
$this->y = $yPayments - 15;
else
$topMargin = 15;
$methodStartY = $this->y;
$this->y -= 15;
foreach ($this->string->split($shippingMethod, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 400, $top + 25, 'UTF-8');
$this->y -= 15;
$yShipments = $this->y;
$totalShippingChargesText = "(" . __(
'Total Shipping Charges'
) . " " . $order->formatPriceTxt(
$order->getShippingAmount()
) . ")";
$page->drawText($totalShippingChargesText, 400, $top + 12, 'UTF-8');
$yShipments -= $topMargin + 10;
$this->y -= -45;
Please Check my Result
add a comment |
override of the abstract class in
appcodeVendorModuleModelOrderPdfInvoice.php
In my case i'm hide that 'red boarded table and update below function insertOrderCustom and adjust element positions via changing $top variable values also comment drawLine codes ,if you need customize below coses basis on your requirement.
protected function insertOrderCustom(&$page, $obj, $putOrderId = true)
if ($obj instanceof MagentoSalesModelOrder)
$shipment = null;
$order = $obj;
elseif ($obj instanceof MagentoSalesModelOrderShipment)
$shipment = $obj;
$order = $shipment->getOrder();
$this->y = $this->y ? $this->y : 815;
$top = $this->y;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->drawRectangle(25, $top, 570, $top - 65);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->setDocHeaderCoordinates([25, $top, 570, $top - 55]);
$this->_setFontRegular($page, 10);
if ($putOrderId)
$page->drawText(__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8');
$page->drawText(
__('Order Date: ') .
$this->_localeDate->formatDate(
$this->_localeDate->scopeDate(
$order->getStore(),
$order->getCreatedAt(),
true
),
IntlDateFormatter::MEDIUM,
false
),
35,
$top -= 15,
'UTF-8'
);
$gstin = $this->_scopeConfig->getValue(
"gst/codilar/gstin",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
if (strlen($gstin)>0)
//$page->drawText(__('GSTIN : ') . $gstin, 35, $top -= 15, 'UTF-8');
$top -= 10;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 275, $top - 25);
$page->drawRectangle(275, $top, 570, $top - 25);
/* Calculate blocks info */
/* Billing Address */
$billingAddress = $this->_formatAddress($this->addressRenderer->format($order->getBillingAddress(), 'pdf'));
$gstin = 'GSTIN: '.$order->getBillingAddress()->getData('gstin');
if($gstin != null)
array_push($billingAddress,$gstin);
/* Payment */
$paymentInfo = $this->_paymentData->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf();
$paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
$payment = explode('pdf_row_separator', $paymentInfo);
foreach ($payment as $key => $value)
if (strip_tags(trim($value)) == '')
unset($payment[$key]);
reset($payment);
/* Shipping Address and Method */
if (!$order->getIsVirtual())
/* Shipping Address */
$shippingAddress = $this->_formatAddress($this->addressRenderer->format($order->getShippingAddress(), 'pdf'));
$shippingMethod = $order->getShippingDescription();
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold to:'), 35, $top - 15, 'UTF-8');
if (!$order->getIsVirtual())
$page->drawText(__('Ship to:'), 285, $top - 15, 'UTF-8');
else
$page->drawText(__('Payment Method:'), 285, $top - 15, 'UTF-8');
$addressesHeight = $this->_calcAddressHeight($billingAddress);
if (isset($shippingAddress))
$addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress));
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - $addressesHeight);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach ($billingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 40, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = $this->y;
if (!$order->getIsVirtual())
$this->y = $addressesStartY;
foreach ($shippingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 40, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = min($addressesEndY, $this->y);
$this->y = $addressesEndY;
$this->y -= 15;
$this->_setFontBold($page, 9.5);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawText(__('Payment Method :'), 300, $top + 40, 'UTF-8');
$page->drawText(__('Shipping Method :'), 300,$top + 25, 'UTF-8');
$this->y -= 10;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->_setFontRegular($page, 10);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$paymentLeft = 35;
$yPayments = $this->y - 15;
else
$yPayments = $addressesStartY;
$paymentLeft = 285;
foreach ($payment as $value)
if (trim($value) != '')
//Printing "Payment Method" lines
$value = preg_replace('/<br[^>]*>/i', "n", $value);
foreach ($this->string->split($value, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 400, $top + 40, 'UTF-8');
$yPayments -= 15;
if ($order->getIsVirtual())
// replacement of Shipments-Payments rectangle block
// $yPayments = min($addressesEndY, $yPayments);
// $page->drawLine(25, $top - 25, 25, $yPayments);
// $page->drawLine(570, $top - 25, 570, $yPayments);
// $page->drawLine(25, $yPayments, 570, $yPayments);
$this->y = $yPayments - 15;
else
$topMargin = 15;
$methodStartY = $this->y;
$this->y -= 15;
foreach ($this->string->split($shippingMethod, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 400, $top + 25, 'UTF-8');
$this->y -= 15;
$yShipments = $this->y;
$totalShippingChargesText = "(" . __(
'Total Shipping Charges'
) . " " . $order->formatPriceTxt(
$order->getShippingAmount()
) . ")";
$page->drawText($totalShippingChargesText, 400, $top + 12, 'UTF-8');
$yShipments -= $topMargin + 10;
$this->y -= -45;
Please Check my Result
override of the abstract class in
appcodeVendorModuleModelOrderPdfInvoice.php
In my case i'm hide that 'red boarded table and update below function insertOrderCustom and adjust element positions via changing $top variable values also comment drawLine codes ,if you need customize below coses basis on your requirement.
protected function insertOrderCustom(&$page, $obj, $putOrderId = true)
if ($obj instanceof MagentoSalesModelOrder)
$shipment = null;
$order = $obj;
elseif ($obj instanceof MagentoSalesModelOrderShipment)
$shipment = $obj;
$order = $shipment->getOrder();
$this->y = $this->y ? $this->y : 815;
$top = $this->y;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->drawRectangle(25, $top, 570, $top - 65);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->setDocHeaderCoordinates([25, $top, 570, $top - 55]);
$this->_setFontRegular($page, 10);
if ($putOrderId)
$page->drawText(__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8');
$page->drawText(
__('Order Date: ') .
$this->_localeDate->formatDate(
$this->_localeDate->scopeDate(
$order->getStore(),
$order->getCreatedAt(),
true
),
IntlDateFormatter::MEDIUM,
false
),
35,
$top -= 15,
'UTF-8'
);
$gstin = $this->_scopeConfig->getValue(
"gst/codilar/gstin",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
if (strlen($gstin)>0)
//$page->drawText(__('GSTIN : ') . $gstin, 35, $top -= 15, 'UTF-8');
$top -= 10;
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $top, 275, $top - 25);
$page->drawRectangle(275, $top, 570, $top - 25);
/* Calculate blocks info */
/* Billing Address */
$billingAddress = $this->_formatAddress($this->addressRenderer->format($order->getBillingAddress(), 'pdf'));
$gstin = 'GSTIN: '.$order->getBillingAddress()->getData('gstin');
if($gstin != null)
array_push($billingAddress,$gstin);
/* Payment */
$paymentInfo = $this->_paymentData->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf();
$paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
$payment = explode('pdf_row_separator', $paymentInfo);
foreach ($payment as $key => $value)
if (strip_tags(trim($value)) == '')
unset($payment[$key]);
reset($payment);
/* Shipping Address and Method */
if (!$order->getIsVirtual())
/* Shipping Address */
$shippingAddress = $this->_formatAddress($this->addressRenderer->format($order->getShippingAddress(), 'pdf'));
$shippingMethod = $order->getShippingDescription();
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontBold($page, 12);
$page->drawText(__('Sold to:'), 35, $top - 15, 'UTF-8');
if (!$order->getIsVirtual())
$page->drawText(__('Ship to:'), 285, $top - 15, 'UTF-8');
else
$page->drawText(__('Payment Method:'), 285, $top - 15, 'UTF-8');
$addressesHeight = $this->_calcAddressHeight($billingAddress);
if (isset($shippingAddress))
$addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress));
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, $top - 25, 570, $top - 33 - $addressesHeight);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->_setFontRegular($page, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
foreach ($billingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 40, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = $this->y;
if (!$order->getIsVirtual())
$this->y = $addressesStartY;
foreach ($shippingAddress as $value)
if ($value !== '')
$text = [];
foreach ($this->string->split($value, 40, true, true) as $_value)
$text[] = $_value;
foreach ($text as $part)
$page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
$this->y -= 15;
$addressesEndY = min($addressesEndY, $this->y);
$this->y = $addressesEndY;
$this->y -= 15;
$this->_setFontBold($page, 9.5);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawText(__('Payment Method :'), 300, $top + 40, 'UTF-8');
$page->drawText(__('Shipping Method :'), 300,$top + 25, 'UTF-8');
$this->y -= 10;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$this->_setFontRegular($page, 10);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$paymentLeft = 35;
$yPayments = $this->y - 15;
else
$yPayments = $addressesStartY;
$paymentLeft = 285;
foreach ($payment as $value)
if (trim($value) != '')
//Printing "Payment Method" lines
$value = preg_replace('/<br[^>]*>/i', "n", $value);
foreach ($this->string->split($value, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 400, $top + 40, 'UTF-8');
$yPayments -= 15;
if ($order->getIsVirtual())
// replacement of Shipments-Payments rectangle block
// $yPayments = min($addressesEndY, $yPayments);
// $page->drawLine(25, $top - 25, 25, $yPayments);
// $page->drawLine(570, $top - 25, 570, $yPayments);
// $page->drawLine(25, $yPayments, 570, $yPayments);
$this->y = $yPayments - 15;
else
$topMargin = 15;
$methodStartY = $this->y;
$this->y -= 15;
foreach ($this->string->split($shippingMethod, 45, true, true) as $_value)
$page->drawText(strip_tags(trim($_value)), 400, $top + 25, 'UTF-8');
$this->y -= 15;
$yShipments = $this->y;
$totalShippingChargesText = "(" . __(
'Total Shipping Charges'
) . " " . $order->formatPriceTxt(
$order->getShippingAmount()
) . ")";
$page->drawText($totalShippingChargesText, 400, $top + 12, 'UTF-8');
$yShipments -= $topMargin + 10;
$this->y -= -45;
Please Check my Result
edited Jul 19 at 4:24
answered Jul 18 at 11:01
Shafeel ShaShafeel Sha
19213 bronze badges
19213 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282456%2fhow-to-edit-invoice-pdf-in-magento-2-3%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you please add again your screenshot?
– Sweety Masmiya
Jul 18 at 4:57
@Sweety Masmiya for what ? you need any clarification ?
– Shafeel Sha
Jul 18 at 5:01
Your image is not display. prnt.sc/oglshg
– Sweety Masmiya
Jul 18 at 5:05
oh sorry please check now, or follow i.stack.imgur.com/tqjMf.jpg
– Shafeel Sha
Jul 18 at 5:06