How To Mail Generated Pdf

I have generated PDF using tcpdf extension …which display content in pdf format…code is below

$pdf = Yii::createComponent('application.extensions.tcpdf.ETcPdf', 'P', 'cm', 'A4', true, 'UTF-8');






$content.='<img src="/logo.jpg" /><br/>'; 

$pdf->writeHTML($content, true, false, false, false, '');


$outPut = $pdf->Output('test.pdf', 'I');


how can i mail this generated PDF in mail with email extension?

Hi chaitsi

You can just attach it in email content as a link of pdf (url on your server),

Here is how I did it:

I have an action with second parameter determing to ouput PDF for download/screen OR a file (which is needed to attach the pdf to an email)

	public function actionPdf($id, $file_output=false)





                if($file_output) {


                } else {




			   'model' => $model,

                           'config' => $xmlConfig,

                           'label' => $label,

                           'filename' => $filename



                if($file_output) {




If $file_output===true a file will be generated and filename is returned (in order to pass it i.e. to your addAttachment method in your mail routine)

Here is the corresponding view:

$pdf = Yii::createComponent('application.extensions.tcpdf.ETcPdf', 

                            'P', 'mm', 'A4', true, 'UTF-8');


[Doing your pdf stuff here]



if(strlen($filename)) {

    $pdf->Output($filename, "F");

} else {    

    $pdf->Output($"-YmdHis").".pdf", "I");


The advantage of this solution is one action and one view for displaying PDF or creating physical files.