首页 > 编程语言 >使用dompdf等php包将html生成为pdf文件

使用dompdf等php包将html生成为pdf文件

时间:2022-11-19 11:14:01浏览次数:40  
标签:content false 包将 new dompdf html PDF pdf

<?php
require_once './libs/tcpdf/vendor/autoload.php';
require_once './libs/mpdf/vendor/autoload.php';
require_once './libs/dompdf/vendor/autoload.php';

$content = '<div style="width: 80%;padding-right: 3rem;padding-left:3rem;margin-right:3rem;margin-left:3rem;">
        <table border="1" style="width: 100%; margin-bottom: 1rem; color: #212529;vertical-align: top;border-color: #dee2e6;border-collapse: collapse;border: 1px solid black;">
            <thead>
                <tr style="height: 4rem;">
                    <th>#</th>
                    <th>First</th>
                    <th>Last</th>
                    <th>Handle</th>
                </tr>
            </thead>
            <tbody>
                <tr style="height: 3rem;">
                    <th scope="row"><input type="checkbox"></th>
                    <td>Mark</td>
                    <td>Otto</td>
                    <td>@mdo</td>
                </tr>
                <tr style="height: 3rem;">
                    <th scope="row"><input type="checkbox"></th>
                    <td>Jacob</td>
                    <td>Thornton</td>
                    <td>@fat</td>
                </tr>
                <tr style="height: 3rem;">
                    <th><input type="checkbox"></th>
                    <td colspan="2">Larry the Bird</td>
                    <td>@twitter</td>
                </tr>
            </tbody>
        </table>
    </div>';

// ob_start();
// $a = 123;
// require('./pdf-temp2.php');
// $content = ob_get_contents();
// ob_end_clean();

// $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// $pdf->SetFont('msyh', '', 8);
// $pdf->setPrintHeader(false);
// $pdf->AddPage();
// $pdf->writeHTML($content, true, false, false, false, '');
// $pdf->Output('example.pdf', 'I');

// $mpdf = new \Mpdf\Mpdf(['UTF-8', 'A4', '', '', 32, 25, 27, 25, 16, 13]);
// $mpdf->writeHTML($content);
// $mpdf->Output();


$dompdf = new \Dompdf\Dompdf();
$dompdf->loadHtml($content);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->output();
// $dompdf->stream(); //输出到浏览器
$dompdf->stream('my.pdf', ['Attachment' => 0]);  //下载
 

 

标签:content,false,包将,new,dompdf,html,PDF,pdf
From: https://www.cnblogs.com/caroline2016/p/16905653.html

相关文章

  • 箭头函数与普通函数的区别、浏览器解析html的过程
    箭头函数与普通函数1.书写方式不同,箭头函数使用箭头定义,普通函数使用关键字 2.this指向不同:箭头:2.11箭头函数本身没有prototype,所以没有自己的this,2.21它的this只能......
  • html生成pdf的js插件的简单使用
    <!DOCTYPEhtml><html><head><metacharset="utf-8"/><title>jspdf</title><linkhref="./plugins/bootstrap-5.1.3-dist/css/bootstrap.min.css"re......
  • 配置实现-自创html生成模板搭配xml获取数据无需写代码实现静态网站
    自创html生成模板搭配xml获取数据无需写代码实现静态网站实际项目:老干部和九重阳网站欢迎访问http://www.laoganbu.orghttp://www.9chongyang.com实现思路:html界面采用自......
  • 去除字符串中的html标签
        ///<summary>    ///将Html标签转化为空贾世义    ///</summary>    ///<paramname="strHtml">待......
  • vscode 如何实时预览 html
    下载LiveServer,随后在html文件处右键,选择Openwithliveserver即可注意可能报错 Openafolderorworkspace...(File->OpenFolder),在页面的左边选择蓝色的......
  • html字符串转pdf源码
        ///<summary>     ///将Html文字输出到PDF     ///</summary>     ///<paramname="htmlText......
  • JavaScript语法_与html结合方式和JavaScript语法_注释&数据类型
    JavaScript语法_与html结合方式:ECMAscript:客户端脚本语言的标准1.基本语法∶与html结合方式1.内部JS:定义<script>,标签体内容就是js代码2.外部JS:定义<script>,通过s......
  • 如何分析html中的json
    在js逆向的过程中,时常要使用正则表达式去匹配htnl的内容,有时候关键的数据都在json中,这个怎么分析这个json呢1.使用vscode打开htmlvscode的js插件会分析html文件,这样就可......
  • html grid 布局与拖动
    1<!DOCTYPEhtml>2<htmllang="en">3<head>4<metacharset="UTF-8"/>5<metahttp-equiv="X-UA-Compatible"content="IE=edge"......
  • 教你快速使用VSCode编写HTML文件
    我的小站——半生瓜のblog教你快速使用VSCode编写HTML文件​​1.配置​​​​2.更改默认打开浏览器​​1.配置首先在官网下载VSCODE并完成安装,[vscode官网]。(https://code.......