织梦引入tcpdf将数据导出为pdf表格。
tcpdf可以在官网下载:https://tcpdf.org/
require_once(DEDEINC.'/tcpdf/tcpdf.php');//引入tcpdf
//创建新的PDF文档
$pdf = new TCPDF('P','mm','A4',true,'UTF-8',false);
//设置文档信息
$pdf->SetCreator('wenjuan');
$pdf->SetAuthor('TCPDF');
$pdf->SetTitle('TCPDF');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, PHP');
// 设置默认标题数据
$pdf->SetHeaderData('',40,'TCPDF','TCPDF',array(0,64,255), array(0,64,128));
$pdf->setFooterData(array(0,64,0), array(0,64,128));
// 设置页眉和页脚字体
$pdf->setHeaderFont(Array('stsongstdlight', '', '10'));
$pdf->setFooterFont(Array('helvetica', '', '8'));
// 设置默认等距字体
$pdf->SetDefaultMonospacedFont('courier');
// 设置边距
$pdf->SetMargins(5,10,5);页面间隔
$pdf->SetHeaderMargin(10);//页眉top间隔
$pdf->SetFooterMargin(10);//页脚bottom间隔
// 设置分页 设置自动分页符
$pdf->SetAutoPageBreak(TRUE, 15);
// 设置图像比例因子
$pdf->setImageScale(1.25);
//设置默认字体子集模式
$pdf->setFontSubsetting(true);
// set font 设置字体
$pdf->SetFont('stsongstdlight','',10,'',true);
// add a page 添加页面
$pdf->AddPage();
//读取数据
$dsql->SetQuery("SELECT * FROM `dede_mm` where id='$id' order by id asc");
$dsql->Execute();
$k=0;
$html = '<!doctype html>';
$html .= '<html lang="en">';
$html .= '<head>';
$html .= '<meta charset="UTF-8" />';
$html .= '<title>tcpdf</title>';
$html .= '</head>';
$html .= '<body>';
$html .="<div>";
while($row=$dsql->GetArray()) {
$k++;
$html .="<span>";
$html .= "<p width=\"90px\">".$k."、".iconv('gbk','utf-8',$row['name'])."(名字):</p>";
$html .= "<table border=\"1\" width=\"100%\"><tr>";
$html .= "<th style="width: 30%;text-align: center;">选项1</th>";
$html .= "<th style="width: 30%;text-align: center;">选项2</th>";
$html .= "<th style="width: 30%;text-align: center;">选项3</th>";
$html .= "</tr>";
$html .= "<tr><td style="text-align: center;">".iconv('gbk','utf-8',$v1)."</td>";
$html .= "<td style="text-align: center;">".$b2."</td>";
$html .= "<td style="text-align: center;">".$m3."</td></tr>";
$html.="</table>";
$html .="</span>";
}
$html .="</div>";
$html .= '</body>';
$html .= '</html>';
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output("tcpdf.pdf","D");
2021/4/23,记录。