首先下载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>