1 頁 (共 1 頁)

A3 PDF

發表於 : 2016-09-23 14:17:01
yehlu
http://stackoverflow.com/questions/1439 ... -a4-and-a5

https://packagist.org/packages/kendu/l5-mpdf

代碼: 選擇全部

$mpdf = new mPDF('',    // mode - default ''
 '',    // format - A4, for example, default ''
 0,     // font size - default 0
 '',    // default font family
 15,    // margin_left
 15,    // margin right
 16,     // margin top
 16,    // margin bottom
 9,     // margin header
 9,     // margin footer
 'L');  // L - landscape, P - portrait

Re: A3 PDF

發表於 : 2016-09-25 17:15:47
yehlu
http://www.jb51.net/article/76023.htm

PHP使用MPDF类生成PDF的方法

作者:jerrylsxu 字体:[增加 减小] 类型:转载 时间:2015-12-08 我要评论
这篇文章主要介绍了PHP使用MPDF类生成PDF的方法 的相关资料,需要的朋友可以参考下
由于公司业务的需要,最近需要把html静态文件生成pdf,在网上找了很多类文件来实现,效果都不是很好.最先用的是tcpdf这个类特别的慢,而且当前版本有一个很让人头疼的问题—css中的背景图片无法获取到,找了很多资料都无法解决.最后发现mpdf可能实现该功能,大喜过望,而且效率也比tcpdf快.
mpdf的官方下载地址:http://www.mpdf1.com/mpdf/download
下载后里面有实例,可以参照着做一个就知道了.当然官方网站也有实例,网址:http://mpdf1.com/common/mpdf/examples/
官方提供的文档:http://mpdf1.com/manual/

代碼: 選擇全部

<?php
/*
*功能:生成用户诊断报告PDF文件
*创建时间:--
*/
//phpinfo();exit;
//引入MPDF类文件
set_time_limit();
include '/include/MPDF/mpdf.php';
//实例化mpdf
$mpdf=new mPDF('utf-','A','','宋体',,,,);
//设置字体,解决中文乱码
$mpdf->useAdobeCJK = true;
$mpdf->SetAutoFont(AUTOFONT_ALL);
//获取要生成的静态文件
$html=file_get_contents('template.html');
echo $html;exit;
//设置PDF页眉内容
$header='<table width="%" style="margin: auto;border-bottom: px solid #FBD; vertical-align: middle; font-family:
serif; font-size: pt; color: #;"><tr>
<td width="%"></td>
<td width="%" align="center" style="font-size:px;color:#AAA">页眉</td>
<td width="%" style="text-align: right;"></td>
</tr></table>';
//设置PDF页脚内容
$footer='<table width="%" style=" vertical-align: bottom; font-family:
serif; font-size: pt; color: #;"><tr style="height:px"></tr><tr>
<td width="%"></td>
<td width="%" align="center" style="font-size:px;color:#AAA">页脚</td>
<td width="%" style="text-align: left;">页码:{PAGENO}/{nb}</td>
</tr></table>';
//添加页眉和页脚到pdf中
$mpdf->SetHTMLHeader($header);
$mpdf->SetHTMLFooter($footer);
//设置pdf显示方式
$mpdf->SetDisplayMode('fullpage');
//设置pdf的尺寸为mm*mm
//$mpdf->WriteHTML('<pagebreak sheet-size="mm mm" />');
//创建pdf文件
$mpdf->WriteHTML($html);
//删除pdf第一页(由于设置pdf尺寸导致多出了一页)
//$mpdf->DeletePages(,);
//输出pdf
$mpdf->Output();
exit;
?>

Re: A3 PDF

發表於 : 2016-09-25 20:32:02
yehlu
自定字形
1.拷貝ttf 檔到 ttffonts 目錄裡
2.在 config_fonts.php 加入字形對照

代碼: 選擇全部

    "fzshusong" => array(
        'R' => "FZShuSong.ttf",
        'B' => "FZShuSong.ttf",
        'I' => "FZShuSong.ttf",
        'BI' => "FZShuSong.ttf",
    ),
    "simhei" => array(
        'R' => "simhei.ttf",
        'B' => "simhei.ttf",
        'I' => "simhei.ttf",
        'BI' => "simhei.ttf",
    ),
字體名稱要用小寫

3.使用範例

代碼: 選擇全部

        $mpdf = new \mPDF('zh-CN', 'A3', '', 'fzshusong', 0, 0, 20, 10);

        .line2 {
          position: absolute;
          font-family:simhei;
          font-size: 30px;
        	overflow: visible;
        	left: 1043;
        	bottom: 862;
        	margin: 0;
        }
        .line3 {
          position: absolute;
          font-family:simhei;
          font-size: 30px;
        	overflow: visible;
        	left: 1043;
        	bottom: 772;
        	margin: 0;
        }