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 / ...
随机推荐
- ini文件读写 保存上次存储内容
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- VSCode 快捷键定义
默认的 Toggle explore side bar 快捷键为 Ctrl + B, 但是这和 Vim 的快捷键冲突,解决方法: File > Preferences > Keyb ...
- Python&Selenium借助html-testRunner生成自动化测试报告
一.摘要 本博文将介绍Python和Selenium进行自动化测试时,借助html-testRunner 生成自动化测试报告 安装命令:pip install html-testRunner 二.测试 ...
- SpringMVC——问题汇总
1.html页面ajax请求/login.后台报: Request method 'GET' not supported 原因: 后台请求使用了method = POST,但是url请求没有formd ...
- jquery 去除 css 的 background-image 样式
首先我使用了这个: $('#**').css('background-image', null); 没有效果...... 然后我用了这个: $('#staffName').css('backgroun ...
- 软raid实现
几种raid类型,我就不在这里赘述了,企业一般都是用raid卡,所以一般使用软raid的非常少,但是也有用的,所以就写一个软raid的实验吧,其实用处不大. 实验环境:centos6.9 需要的硬件: ...
- redis主从+哨兵 安装配置二
实验环境: 192.168.2.201 centos7 master sentinel 192.168.2.202 centos7 slave sentinel 192.168.2.203 cen ...
- Codeforces Round #588 (Div. 2) C. Anadi and Domino(思维)
链接: https://codeforces.com/contest/1230/problem/C 题意: Anadi has a set of dominoes. Every domino has ...
- awk_printf
awk -F: 'BEGIN{printf "%-20s%-20s%-20s\n","User","UID","Home" ...
- PHP实现yii项目转发有哪几种方法?
header("location: index.php"); 如果header后面有代码, 会执行, 如果不想执行, 则加上exit;或者die();等, 应该可以应用到yii项目 ...