dede使用tcpdf导出pdf文件

2 篇文章 0 订阅

                                                         织梦引入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,记录。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值