Yii Framework Forum: How To Mail Generated Pdf - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Mail Generated Pdf Rate Topic: -----

#1 User is offline   chaitsi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 21-November 11

Posted 24 November 2012 - 04:40 AM

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');
$pdf->SetCreator(PDF_CREATOR);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->AliasNbPages();
$pdf->AddPage();

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

$pdf->writeHTML($content, true, false, false, false, '');
$pdf->LastPage();
$outPut = $pdf->Output('test.pdf', 'I');
Yii::app()->end();


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

#2 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,335
  • Joined: 21-February 11
  • Location:Greece

Posted 24 November 2012 - 08:13 AM

Hi chaitsi

You can just attach it in email content as a link of pdf (url on your server),
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   guaruja 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 72
  • Joined: 10-March 12

Posted 01 December 2012 - 01:54 PM

View Postchaitsi, on 24 November 2012 - 04:40 AM, said:

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');
$pdf->SetCreator(PDF_CREATOR);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->AliasNbPages();
$pdf->AddPage();

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

$pdf->writeHTML($content, true, false, false, false, '');
$pdf->LastPage();
$outPut = $pdf->Output('test.pdf', 'I');
Yii::app()->end();


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


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)
	{                              
                $model=$this->loadModel($id);

				..... 
                
                if($file_output) {
                    $filename=Yii::app()->params['pathPdfTemp'].$label.date("-YmdHis").'.pdf';
                } else {
                    $filename='';
                }
		        $this->renderPartial('pdf',array(
			   'model' => $model,
                           'config' => $xmlConfig,
                           'label' => $label,
                           'filename' => $filename
		        ));
                
                if($file_output) {
                    return($filename);
                }
	}


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($label.date("-YmdHis").".pdf", "I");
}


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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users