Just to consolidate all this information:
1: Create (or use) a custom module under app/code/YourModule
- eg app/code/YourModule/Sales
2: Add a <preference \>
entry to app/code/YourModule/Sales/etc/di.xml
- eg:
<?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="YourModule\Sales\Model\Order\Pdf\Invoice" />
</config>
3: Create the file app/code/YourModule/Sales/Model/Order/Pdf/Invoice.php
<?php
namespace YourModule\Sales\Model\Order\Pdf;
/**
* Use built-in fonts in PDFs so that invoices are smaller.
*
*/
class Invoice extends \Magento\Sales\Model\Order\Pdf\Invoice
{
protected function _setFontRegular($object, $size = 7)
{
$font = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA); // or FONT_TIMES for serif
$object->setFont($font, $size);
return $font;
}
protected function _setFontBold($object, $size = 7)
{
$font = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA_BOLD); // or FONT_TIMES_BOLD for serif
$object->setFont($font, $size);
return $font;
}
protected function _setFontItalic($object, $size = 7)
{
$font = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA_ITALIC); // or FONT_TIMES_ITALIC for serif
$object->setFont($font, $size);
return $font;
}
}
That will reduce your invoices from 3Mb each to 2Kb.