0

I Have Custom Module For Send Email.

But I Want To Send Pdf Same As Email.

I Want To Convert My Email Template To PDF And Attach It to Email Magento 2.3

0

Using dompdf

Define in email_templates.xml :-

 <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
    <template id="custom_template_id" label="custom_template_id" file="pdftemplate.html" type="html" module="Vendor_Module" area="frontend"/>
</config>

Get Email Template As Html :-

$testTemplate = $this->templateFactory->get('custom_template_id') //template Identifier
                ->setVars($templateVars)
                ->setOptions($templateOptions);

        $html = $testTemplate->processTemplate();

Create PDF :-

$dompdf = new Dompdf();

$dompdf->loadHtml($html); //$html is html of template

$dompdf->setPaper('A4', 'portrait');

$dompdf->render();
  • Once this is done, you need to create "addAttachment" method in your transport class. – Rahul Anand Aug 30 at 6:06
  • public function addAttachment( $body, $mimeType = Zend_Mime::TYPE_OCTETSTREAM, $disposition = Zend_Mime::DISPOSITION_ATTACHMENT, $encoding = Zend_Mime::ENCODING_BASE64, $filename = null ) { $this->message->createAttachment($body, $mimeType, $disposition, $encoding, $filename); return $this; } – Rahul Anand Aug 30 at 6:10

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.