前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PHP使用mpdf下载PDF文件

PHP使用mpdf下载PDF文件

原创
作者头像
Action
修改2021-05-07 14:30:46
3.5K0
修改2021-05-07 14:30:46
举报
文章被收录于专栏:WEB开发~

官网

https://mpdf.github.io/

安装

代码语言:txt
复制
composer require mpdf/mpdf

使用

代码语言:txt
复制
<?php

require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf([
	'orientation' => 'L', //设置为横屏
	'margin_top' => '0', //设置上边距
	'margin_bottom' => '0' ,//设置下边距
	'format' => [190, 236], //纸张大小
	'mode' => 'utf-8',
]);



$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$mpdf->use_kwt = false;

$html = "<table style='text-align:center'>
            <tr>
                <th><h1>Hello world!</h1></th>
            </tr>
             <tr>
                <th><h1>Hello world!</h1></th>
            </tr>
             <tr>
                <th><h1>Hello world!</h1></th>
            </tr>
             <tr>
                <th><h1>Hello world!</h1></th>
            </tr>
        </table>";

//设置水印文字
$mpdf->SetWatermarkText('Water');
$mpdf->showWatermarkText = true; 
//设置水印图片
$mpdf->SetWatermarkImage('./background.jpg');
$mpdf->showWatermarkImage = true;


$mpdf->WriteHTML($html);
$mpdf->Output('mpdf.pdf', 'I'); //D是下载

效果

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 官网
  • 安装
  • 使用
  • 效果
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档