下载后把文件夹解压到如下路径
引入mpdf类并调用生成pdf的方法
/** * 导出pdf文件 * www.shouce.ren */ public function actionPdf() { $ds = DIRECTORY_SEPARATOR; Yii::$enableIncludePath = false; Yii::import('application.extensions.mpdf.mpdf', 1); $mpdf=new mPDF('','A4', 0, '', 0, 0); $mpdf->autoScriptToLang = true; $mpdf->autoLangToFont = true; // $sign_path=''; // //$mpdf->SetWatermarkImage($sign_path, 1, '', ''); // $mpdf->WriteHTML('<style>body {background-image:url('.$sign_path.'); background-image-resize:1}</style>'); // $mpdf->showWatermarkImage = true; // $mpdf=new mPDF('UTF-8','A4','','',15,15,44,15); // $mpdf->useAdobeCJK = true; // $mpdf->SetAutoFont(AUTOFONT_ALL); // $mpdf->SetDisplayMode('fullpage'); // //$mpdf->watermark_font = 'GB'; // //$mpdf->SetWatermarkText('中国水印',0.1); // $url = 'http://www.你的域名.com/'; // $strContent = file_get_contents($url); // //print_r($strContent);die; // $mpdf->showWatermarkText = true; // $mpdf->SetAutoFont(); // //$mpdf->SetHTMLHeader( '头部' ); // //$mpdf->SetHTMLFooter( '底部' ); // $mpdf->WriteHTML($strContent); // $mpdf->Output('ss.pdf'); // //$mpdf->Output('tmp.pdf',true); // //$mpdf->Output('tmp.pdf','d'); // //$mpdf->Output(); // $stylesheet =file_get_contents('themes/wei/css/bootstrap.min.css'); // $mpdf->WriteHTML($stylesheet, 1); $ds = DIRECTORY_SEPARATOR; $date_path =date('Y/m').'/'; $pdf_path = Yii::app()->basePath.$ds.'data'.$ds.'pdf'.$ds.$date_path; if(!file_exists($pdf_path)) mkdir($pdf_path,777,true); $content ='这是内容也可以引入一个html页面'; $mpdf->WriteHTML($content); //$mpdf->Output($pdf_path); $mpdf->Output('2015.pdf',true); }
前台直接调用这个方法即可生成pdf文件。