php生成pdf格式的文件
2015-05-17 16:41
609 查看
首先下载TCPDF文件
然后require_once导入tcpdf.php文件,实例化TCPDF配置相关信息;
例如:
include_once("libs/tcpdf/tcpdf.php");
require_once('libs/tcpdf/config/eng.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(16, 6);
$pdf->SetRightMargin(10);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setLanguageArray($l);
$pdf->SetFont('stsongstdlight', '', 13);
$pdf->AddPage();
$outpdf=$smarty->fetch('pdf.html');
$pdf->writeHTML($outpdf, true, 0, true, 0);
$pdf->Output("files/$orderNo.pdf", 'F');//若要显示pdf出可用I
我的df.html代码如下(模板用smarty了)
<style>
ul,li{list-style:none;}
</style>
</head>
<body style="background:#ccc;">
<table style="width:80%;float:right;">
<tr><td></td><td>估價單<ul><li>發出日期:<{$order.buyDate|date_format:'%Y-%m-%d'}></li><li>客戶說明:<{$order.username}>+<{$order.comName}></li><li>估價單編號#:<{$order.orderNo}></li><li>估價有效日期:<{$order.deadDate|date_format:'%Y-%m-%d'}></li><li>付款條件:30天</li></ul></td></tr>
<tr><td>寄至<ul><li>marey liao</li><li>Dentsu</li><li>taiwan taiwan,taiwan100</li><li>Taiwan</li></ul></td><td></td></tr>
<tr>
<td colspan=2>
<table>
<tr><th></th><th>細節</th><th>總額</th></tr>
<{foreach from=$order_detail key=key item=detail}>
<tr>
<td><img src="smallImage/<{$detail.smaImage}>"/></td>
<td><{$detail.prodtype}>+<{$detail.proId}>+<{$detail.size}>+<{$detail.buytime}></td>
<td><{$detail.pricetotal}></td>
</tr>
<{/foreach}>
</table>
</td>
</tr>
<tr><td>固定文字</td><td><ul><li>小計:<{$order.total}></li><li>折扣:<{$discounts}></li><li>營業稅:<{$order.tax}></li><li>總金額:<{$order.pay}></li></ul></td></tr>
<tr><td></td><td>客戶簽名:</td></tr>
</table>
</body>
</html>
然后require_once导入tcpdf.php文件,实例化TCPDF配置相关信息;
例如:
include_once("libs/tcpdf/tcpdf.php");
require_once('libs/tcpdf/config/eng.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(16, 6);
$pdf->SetRightMargin(10);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setLanguageArray($l);
$pdf->SetFont('stsongstdlight', '', 13);
$pdf->AddPage();
$outpdf=$smarty->fetch('pdf.html');
$pdf->writeHTML($outpdf, true, 0, true, 0);
$pdf->Output("files/$orderNo.pdf", 'F');//若要显示pdf出可用I
我的df.html代码如下(模板用smarty了)
<style>
ul,li{list-style:none;}
</style>
</head>
<body style="background:#ccc;">
<table style="width:80%;float:right;">
<tr><td></td><td>估價單<ul><li>發出日期:<{$order.buyDate|date_format:'%Y-%m-%d'}></li><li>客戶說明:<{$order.username}>+<{$order.comName}></li><li>估價單編號#:<{$order.orderNo}></li><li>估價有效日期:<{$order.deadDate|date_format:'%Y-%m-%d'}></li><li>付款條件:30天</li></ul></td></tr>
<tr><td>寄至<ul><li>marey liao</li><li>Dentsu</li><li>taiwan taiwan,taiwan100</li><li>Taiwan</li></ul></td><td></td></tr>
<tr>
<td colspan=2>
<table>
<tr><th></th><th>細節</th><th>總額</th></tr>
<{foreach from=$order_detail key=key item=detail}>
<tr>
<td><img src="smallImage/<{$detail.smaImage}>"/></td>
<td><{$detail.prodtype}>+<{$detail.proId}>+<{$detail.size}>+<{$detail.buytime}></td>
<td><{$detail.pricetotal}></td>
</tr>
<{/foreach}>
</table>
</td>
</tr>
<tr><td>固定文字</td><td><ul><li>小計:<{$order.total}></li><li>折扣:<{$discounts}></li><li>營業稅:<{$order.tax}></li><li>總金額:<{$order.pay}></li></ul></td></tr>
<tr><td></td><td>客戶簽名:</td></tr>
</table>
</body>
</html>
相关文章推荐
- php生成PDF格式文件并且加密
- php生成PDF格式文件并且加密
- 读取Excel 将每条记录单独生成自定义格式的PDF文件
- asp生成pdf格式文件的方法
- php生成pdf文件代码(1/12)
- php生成PDF文件(FPDF)
- 关于Java Web 使用 iText 将数据库中的 表 的数据 生成 PDF 格式文件(升級版本)
- 读取Excel 将每条记录单独生成自定义格式的PDF文件
- ThinkPHP5/PHP 使用TCPDF 生成PDF文件
- php生成PDF文件(FPDF)
- 用PHP生成PDF文件 with FPDF
- 读取Excel 将每条记录单独生成自定义格式的PDF文件
- 用PHP生成PDF文件 with FPDF
- PHP实现HTML生成PDF文件的方法
- 将PDF格式文件转成二进制并生成Base64编码,将Base64编码转成PDF文件
- [轉載]史上最强php生成pdf文件,html转pdf文件方法
- php实现生成PDF文件的方法示例【基于FPDF类库】
- php使用TCPDF生成PDF文件教程
- 在Linux上将12导联心电文件生成PDF格式文件