Created
June 17, 2022 13:43
-
-
Save zepgram/74fca9ffd358bb44e4875c6378b2e609 to your computer and use it in GitHub Desktop.
PDF size reduction for Magento 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace MyNamespace\Sales\Model\Order\Pdf; | |
use Magento\Sales\Model\Order\Pdf\AbstractPdf as MagentoAbstractPdf; | |
/** | |
* Drastically reduce size of PDF by changing fonts | |
*/ | |
abstract class AbstractPdf extends MagentoAbstractPdf | |
{ | |
protected function _setFontRegular($object, $size = 7) | |
{ | |
$font = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_TIMES); | |
$object->setFont($font, $size); | |
return $font; | |
} | |
protected function _setFontBold($object, $size = 7) | |
{ | |
$font = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_TIMES_BOLD); | |
$object->setFont($font, $size); | |
return $font; | |
} | |
protected function _setFontItalic($object, $size = 7) | |
{ | |
$font = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_TIMES_ITALIC); | |
$object->setFont($font, $size); | |
return $font; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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\AbstractPdf" type="MyNamespace\Sales\Model\Order\Pdf\AbstractPdf" /> | |
</config> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment