zoukankan      html  css  js  c++  java
  • html生成pdf

    链接:http://mpdf.github.io/

    需下载包https://packagist.org/packages/mpdf/mpdf

    ob_clean();
    ob_start();
    $this->display('catalogue/export');
    $html = ob_get_contents(); // retrieve buffer contents
    ob_end_clean();

    require_once ROOT_PATH . '/Public/mpdf60/mpdf.php';
    //实例化mpdf $mode='',$format='A4',$default_font_size=0,$default_font='',$mgl=15,$mgr=15,$mgt=16,$mgb=16,$mgh=9,$mgf=9, $orientation='P'
    // $mpdf = new mPDF('utf-8', 'A4', 10, '微软雅黑', 10, 10, 20, 20);
    $mpdf = new mPDF('utf-8', 'A4', 10, 'siyuanhei', 0, 0, 0, 0, 0, 0);
    //设置字体,解决中文乱码
    $mpdf->useAdobeCJK = true;
    $mpdf->autoLangToFont = true;
    $mpdf->autoScriptToLang = true;
    //设置PDF页眉内容
    // $header = '<div style="float:right;font-size:12px;color:#000;text-align:right;vertical-align:bottom;">引领客户实现组织效能与人才价值最大化</div>';

    //设置PDF页脚内容
    // $footer = '<div style="float:right;text-align:right;font-size:12px;">第{PAGENO}页/共{nb}页</div>';

    //添加页眉和页脚到pdf中
    // $mpdf->SetHTMLHeader($header);
    // $mpdf->SetHTMLFooter($footer);
    //设置pdf显示方式
    $mpdf->SetDisplayMode('fullpage');
    //设置pdf的尺寸为270mm*397mm
    //$mpdf->WriteHTML(‘<pagebreak sheet-size=”270mm 397mm” />’);
    $mpdf->watermark_font = 'GB';
    // $mpdf->SetWatermarkText('华夏智业', 0.1);
    $mpdf->showWatermarkText = true;
    //创建pdf文件
    $mpdf->WriteHTML($html);
    //删除pdf第一页(由于设置pdf尺寸导致多出了一页)
    //$mpdf->DeletePages(1,1);
    //输出pdf $name);$projectname
    $mpdf->Output($name.'.pdf', TRUE); #. '_' . date('YmdHis')

    目录:
    <bookmark content="目录" />
    <tocpagebreak links="on" toc-margin-left="30mm" toc-margin-right="30mm" toc-margin-top="30mm" toc-margin-bottom="30mm" toc-odd-header-name="html_toch" toc-odd-header-value="on" toc-odd-footer-name="html_tocf" toc-odd-footer-value="on" toc-resetpagenum="1" toc-pagenumstyle="I" resetpagenum="1" margin-left="30mm" margin-right="30mm" margin-top="30mm" margin-bottom="30mm" odd-header-name="html_contenth" odd-header-value="on" odd-footer-name="html_contentf" odd-footer-value="on" pagenumstyle="1" paging="0"/>
    <bookmark content="<?php echo $tv['text']; ?>" />
    <tocentry content="<?php echo $tv['text']; ?>" />
    <bookmark content="<?php echo $tv1['text']; ?>" level="1" />
    <tocentry content="<?php echo $tv1['text']; ?>" level="1" />



  • 相关阅读:
    excel如何设置输入数字后单元格自动填充颜色
    怎样在excel中添加下拉列表框
    System.Security.Cryptography.CryptographicException 出现了内部错误
    怎样让webservice在浏览器远程浏览时像在本地浏览一样有参数输入框
    EF实体框架常见问题
    jdk安装环境变量设置
    IIS网站部署注意点
    浏览器被hao.360.cn劫持怎么办
    python-字典
    python-list列表
  • 原文地址:https://www.cnblogs.com/chouxiao/p/13553119.html
Copyright © 2011-2022 走看看