How to show order comments history in PDF shipping
vendor/magento/module-sales/Model/Order/Pdf/invoice.php
di.xml
<?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\Invoice" type="Vendor\Module\Model\Rewrite\Order\Pdf\Invoice" />
</config>
app/code/Vendor/Module/Model/Rewrite/Order/Pdf/Invoice.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Vendor\Module\Model\Rewrite\Order\Pdf;
use Magento\Sales\Model\ResourceModel\Order\Invoice\Collection;
use Magento\Sales\Model\Order\Pdf\AbstractPdf;
class Invoice extends AbstractPdf
{
/**
* Return PDF document
*
* @param array|Collection $invoices
* @return \Zend_Pdf
*/
public function getPdf($invoices = [])
{
echo "Model Rewrite Working"; die();
$this->_beforeGetPdf();
$this->_initRenderer('invoice');
$pdf = new \Zend_Pdf();
$this->_setPdf($pdf);
$style = new \Zend_Pdf_Style();
$this->_setFontBold($style, 10);
foreach ($invoices as $invoice) {
if ($invoice->getStoreId()) {
$this->_localeResolver->emulate($invoice->getStoreId());
$this->_storeManager->setCurrentStore($invoice->getStoreId());
}
$page = $this->newPage();
$order = $invoice->getOrder();
foreach ($_entity->getOrder()->getStatusHistoryCollection() as $status){
$textChunk = wordwrap($status->getComment(), 120, "\n");
foreach(explode("\n", $textChunk) as $textLine){
if ($textLine!=='') {
$page->drawText(strip_tags(ltrim($textLine)), 35, $this->y, 'UTF-8');
$this->y -= 15;
}
}
}
$this->_afterGetPdf();
return $pdf;
}
}