PHP yii2.0框架利用mpdf导出pdf
安装:
composer require mpdf/mpdf
使用:
use Mpdf\Mpdf;//(php7以前)
//获取页面内容
$res = $this->controller->render('tb-plan/clonePdf', [
'cms_intro'=>$cms_intro,
'corp_name'=>$corp_name,
'order'=>$order,
'intro'=>$intro,
'cmsDaily'=>$val,
'priceConf'=>$priceConf,
'people'=>$people
]);
$mpdf=new Mpdf(['zh-CN','A4','','',23,23,40,'setAutoTopMargin' => 'stretch']);
//设置中文字符集
$mpdf->useAdobeCJK = true;
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
//设置PDF页眉内容
$header='<table width="95%" style="margin:0 auto; vertical-align: middle; font-family:
serif; font-size: 9pt; color: #000088;"><tr>
<td width="10%"><img src="//i0.h34n32i1u.cn/a123/123/pdfLogo.jpg" alt="" width="30%"></td>
<td width="40%" align="center"></td>
<td width="50%" style="text-align: right;font-size: 20px;color: #1a1a1a;">订单ID:'.$order_id.'</td>
</tr></table>';
//设置PDF页脚内容
$footer='<table width="100%" style=" vertical-align: bottom; font-family:
serif; font-size: 9pt; color: #000088;"><tr style="height:30px"></tr><tr>
<td width="48%" style="font-size:14px;color:#A0A0A0">ADD:上海市联航路1688弄</td>
<td width="4%" align="center"></td>
<td width="48%" style="text-align: right;font-size:14px;color:#A0A0A0">TEL:0000-000-000</td>
</tr></table>';
//添加页眉和页脚到pdf中
$mpdf->SetHTMLHeader($header);
$mpdf->SetHTMLFooter($footer);
//设置pdf显示方式
$mpdf->SetDisplayMode('fullpage');
//设置水印
$mpdf->SetWatermarkImage('//i0.hiniu.cn/a3/180121/Watermark.png',1,'F');
$mpdf->showWatermarkImage = true;
//加载css
$style1=file_get_contents(Html::loadFile('tj-pc-3.0/dist/all.min.css'));
$style2=file_get_contents(Html::loadFile('vendor/bootstrap/2.3.2/css/bootstrap.min.css'));
$mpdf->WriteHTML($style1,1);
$mpdf->WriteHTML($style2,1);
//写入数据
$mpdf->WriteHTML($res);
$userName=$admin->real_name;
unset($res);
// 记录修改历史
AdminLogDataOperate::add('用户【'.$userName.'】为【'.$corp_name.'】生成PDF', '系统', AdminLog::TYPE_ORDER_PDF, $order_id, AdminLog::ID2_T1);
AdminLogDataOperate::add('用户【'.$userName.'】为【'.$corp_name.'】生成PDF', 'now_admin', AdminLog::TYPE_ORDER_PDF, $order_id, AdminLog::ID2_T2);
$fileName=date('YmdHis',time()).'.pdf';
//下载pdf
$mpdf->Output($fileName,'D');
<?php require_once __DIR__ . '/vendor/autoload.php';//(php7) $mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->Output();//$mpdf->Output('php://output');
require_once Yii::getAlias('@vendor/mpdf/autoload.php');
header('Content-Type: application/pdf'); // PDF文件
header('Content-Transfer-Encoding: binary');
header('Cache-Control: max-age=1');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: cache, must-revalidate');
header('Pragma: public');
header('Content-Disposition: attachment; filename=' . $title . '.pdf'); //指定文件名称
header("Expires: 0");
$mpdf = new \Mpdf\Mpdf();
$mpdf->SetDisplayMode('fullpage');
$mpdf->SetWatermarkImage($url,1,'F');
$mpdf->showWatermarkImage = true;
$mpdf->Output('php://output');
PHP yii2.0框架利用mpdf导出pdf的更多相关文章
- 在 yii2.0 框架中封装导出html 表格样式 Excel 类
在 vendor/yiisoft/yii2/helpers/ 创建一个 Excel.php <?php namespace yii\helpers; class Excel{ ...
- yii2.0框架安装心得
yii2.0安装心得 能够搜索到这篇文章的朋友相信是对yii框架有兴趣的,但是我不得不吐槽的是,这个安装过程确实让人头疼,接下来就让大家见证一下这个纠结的过程 根据官网的说法,安装这个框架需要用到co ...
- 8.Yii2.0框架控制器接收get.post数据
8.Yii2.0框架控制器接收get.post数据 一.get传参 <?php /** * Created by Haima. * Author:Haima * QQ:228654416 * D ...
- 利用FR导出PDF汉字乱码的处理
利用FR导出pdf,然后在unigui中显示,发现汉字乱码,改成gb2312,不乱码,但不自动折行,最后是改成DefaultCharSet搞定.FR版本:5.4.6 后记:有的浏览器中还是乱码,把字体 ...
- 利用ITextSharp导出PDF文件
最近项目中需要到处PDF文件,最后上网搜索了一下,发现ITextSharp比较好用,所以做了一个例子: public string ExportPDF() { //ITextSharp Usage / ...
- java利用itext导出pdf
项目中有一功能是导出历史记录,可以导出pdf和excel,这里先说导出pdf.在网上查可以用那些方式导出pdf,用itext比较多广泛. 导出pdf可以使用两种方式,一是可以根据已有的pdf模板,进行 ...
- 利用itext导出PDF的小例子
我这边使用的jar包: itext-2.1.7.jar itextasian-1.5.2.jar 代码,简单的小例子,导出pdf: PdfService.java: package com.cy.se ...
- Itext2.0.8 和freemarker导出pdf
这个是跟上一篇写的freemarker导出word是一块的.但是关联性不是很大.由于本人技术有限本篇导出也是根据网上大家的做出的demo混合而成.有不足的地方请大家指出.好改正,使以后看到的freem ...
- C# 利用ITextSharp导出PDF文件
最近项目中需要导出PDF文件,最后上网搜索了一下,发现ITextSharp比较好用,所以做了一个例子: public string ExportPDF() { //ITextSharp Usage / ...
随机推荐
- 关于pycharm database查看db.sqlites文件提示:Driver class 'org.sqlite.JDBC' not found
系统重新安装后,启动pycharm存在各种问题,其中一个问题就是在Pycharm中的database里面不能查看sqlite数据库了: 经过一番查找终于找到了问题: 首先问题 是提示这样一个报错: 解 ...
- 树的总结(遍历,BST,AVL原型,堆,练习题)
目录 树 一.抽象数据类型 二.二叉树的性质 三.二叉树的遍历 三.活用树的遍历 四.BST树 五.AVL树 六.BST树和AVL树练习 七.堆 树 @ 一.抽象数据类型 1.顺序存储 使用数组存储 ...
- SQL 查询今天、昨天、7天内、30天的数据
今天的所有数据: 昨天的所有数据: 7天内的所有数据: 30天内的所有数据: 本月的所有数据: 本年的所有数据: 查询今天是今年的第几天: select datepart(dayofyear,getD ...
- 一段有关线搜索的从python到matlab的代码
在Udacity上很多关于机器学习的课程几乎都是基于python语言的,博主“ttang”的博文“重新发现梯度下降法——backtracking line search”里对回溯线搜索的算法实现也是用 ...
- CF666E Forensic Examination——SAM+线段树合并+倍增
RemoteJudge 题目大意 给你一个串\(S\)以及一个字符串数组\(T[1...m]\),\(q\)次询问,每次问\(S\)的子串\(S[p_l...p_r]\)在\(T[l...r]\)中的 ...
- 使用memocache
直接cmd下运行 pip3 install python-memcached serializer.py 里的特别应用 如果一个表模型一些字段用到了跨表.可以这样取值 跨表字段 coach_nickn ...
- 生成和安装requirements.txt依赖
pip freeze > requirements.txt pip install -r < requirements.txt
- 【ArcMap】
1.加载图层(1)内容列表中右键添加数据(2)目录列表中拖拽(3)导航中的添加数据 2.编辑要素(1)选中编辑器点击开始编辑(2)在编辑要素中选中要编辑的要素 选择构造工具 执行编辑操作(3)停止编辑 ...
- 中介者模式(Mediator)---行为型
1 基础知识 定义:用一个中介对象来封装一系列的对象交互.中介者使得各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互. 本质:封装交互 使用场景:(1)如果一组对象之间的 ...
- 路由器配置——OSPF协议(2)
一.实验目的:使用OSPF协议达到全网互通的效果 二.拓扑图 三.具体步骤配置 (1)R1路由器配置 Router>enableRouter#configure terminalEnter co ...