1

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

asked Aug 27, 2019 at 11:58

1 Answer 1

1

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();
answered Aug 30, 2019 at 5:22
2
  • Once this is done, you need to create "addAttachment" method in your transport class. Commented Aug 30, 2019 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; } Commented Aug 30, 2019 at 6:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.