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
Ronak Rathod
6,58020 silver badges46 bronze badges
1 Answer 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
Ronak Rathod
6,58020 silver badges46 bronze badges
-
Once this is done, you need to create "addAttachment" method in your transport class.Rahul Anand– Rahul Anand2019年08月30日 06:06:04 +00:00Commented 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; }Rahul Anand– Rahul Anand2019年08月30日 06:10:04 +00:00Commented Aug 30, 2019 at 6:10
default