为了账号安全,请及时绑定邮箱和手机立即绑定

php 使用tcpdf库输出pdf

标签:
PHP API

新建demo.php

<?php

    require_once("tcpdf/tcpdf.php");

    $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', true);

    //设置PDF页面边距 LEFT, TOP, RIGHT

    //$pdf->SetMargins(20, 20, 20);


    //设置文件信息

    $pdf->SetCreator(TITLE_NAME);

    $pdf->SetAuthor(TITLE_NAME);

    $pdf->SetTitle("这是标题");


    //删除预定义的打印 页眉/页尾

    $pdf->setPrintHeader(false);

    /*

    $pdf->setHeaderFont(Array('stsongstdlight', '', '10'));

    //多行文本会显示不全,通过SetMargins中的top设置,可以显示更多的头部内容

    //第一个arrary是设置头文本颜色,第二个是设置横线颜色

    $pdf->SetHeaderData('logo.png', 30, '第一行',"第二行\n換行內容", array(30,54,25), array(30,54,25));

    $pdf->SetHeaderMargin(5);

    */

    $pdf->setPrintFooter(false);

    /*

    $pdf->setFooterFont(Array('stsongstdlight', '', '8'));

    $pdf->SetFooterMargin(10);

    */

    //设置默认等宽字体

    $pdf->SetDefaultMonospacedFont('courier');

    //设置默认字体构造子集模式,设置false将把字体嵌入到pdf中(文件会变大)

    $pdf->setFontSubsetting(false);

    //设置字体,字体在fonts目录中。

    //有时设置字体后会发现html中不能设粗体或斜体,这和字体本身有关

    //解决方法再生成粗体和斜体字体,命名为**b、**i(例如fzssjwb、fzssjwi)

    //这时在css中使用<b>、<h1>等标签就会自动加粗

    //$pdf->SetFont('freemonob');

    $pdf->SetFont('msungstdlight','',16);

    //设置自动换页

    $pdf->SetAutoPageBreak(true, 20);

    $html = file_get_contents("demo.html");

    //添加一个页面

    $pdf->AddPage();

    // output the HTML content

    $pdf->writeHTML($html, true, false, true, false, '');

    $pdf->lastPage();

    $pdf->Output("test001.pdf", "I");

?>


同级目录下新建demo.html

<!DOCTYPE html>

<style>

    body{

        width: 200mm;

        height: 240mm;

        margin: 15mm auto;

        padding: 0;

        font-size: 10.5pt;

        border: black 1px solid;

        /* font-family: "simsun"; */

    }

    .container {

        height: 180mm;

        width: 155mm;

        margin: 100px auto;

    }

    table{

        letter-spacing: 2px;

        line-height: 30px;

        width: 100%;

        border-collapse: collapse;

        table-layout: fixed;

    }

    .content {

        margin-top: 40px;

    }

    .between {

        margin-left: 30px;

        margin-top: 20px;

    }

    .between input{

        width: 300px;

        margin: 3mm 0;

    }

    .foot {

        margin-top: 100px;

    }

    .foot table {

        letter-spacing: 3.5px;

    }

    .qz {

        margin-top: 30px;

    }

    .qz table {

        line-height: 40px;

    }

    .table {

        float: right;

    }

    .foot span {

        text-decoration: black solid ;

        border-bottom: 1px black solid;

    }

    h1{

        text-align:center;

    }

</style>

<body>

<div class="container">

    <h1>授权委托书</h1>

    <div class="content">

        <table>

            <tr>

                <td>&nbsp;&nbsp;现本人不可撤销的向 ******* 银行</td>

            </tr>

            <tr>

                <td><strong>授权:</strong></td>

            </tr>

            <tr>

                <td style="letter-spacing: 6px">&nbsp;&nbsp;本人因办理 *********** 业务,已经</td>

            </tr>

            <tr>

                <td>向 0000000 公司支付首付款,现委托贵</td>

            </tr>

            <tr>

                <td>行将本人的信用卡(卡号 234234234342)</td>

            </tr>

            <tr>

                <td>进行启用,并将其余款项 **** 元,</td>

            </tr>

            <tr>

                <td>以透支形式扣收后支付给该公司,入账账户信息如下:</td>

            </tr>

        </table>

    </div>

    <div class="between">

        <table>

            <tr>

                <td colspan="1" class="table">账户名称:</td>

                <td colspan="4"><input type="text"  value="{$info.zhmc|default=$gs_name}" id="zhmc"></td>

            </tr>

            <tr>

                <td colspan="1" class="table">账&nbsp;&nbsp;号:</td>

                <td colspan="4"><input type="text" value="{$info.zh|default=$bank_number}" id="zh"></td>

            </tr>

            <tr>

                <td colspan="1" class="table"><span style="letter-spacing: 11px">开户</span>行:</td>

                <td colspan="4"> ********** </td>

            </tr>

        </table>

    </div>


    <div class="foot">

        <table>

            <tr>

                <td>&nbsp;&nbsp;<span>本人在签署此授权委托书之前,已认真仔细阅读上述内容,清</span></td>

            </tr>

            <tr>

                <td><span>楚知晓并自愿承担由此引发的相关法律责任。</span></td>

            </tr>

        </table>

    </div>


    <div class="qz">

        <table>

            <tr>

                <td colspan="5"></td>

                <td colspan="4">授权人:</td>

            </tr>

            <tr>

                <td colspan="6"></td>

                <td colspan="3">2019年04月01日</td>

            </tr>

        </table>

    </div>

</div>

</body>

运行demo.php 如果提示字体错误,未找到字体,去官网下载完整版fonts


点击查看更多内容
1人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消