1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace app\index\controller;
- use think\facade\View;
- class Pdf extends Base
- {
- /*
- * 文档:https://tcpdf.org/examples/
- * composer 安装命令:composer require tecnickcom/tcpdf
- *
- * */
- /**
- * @var bool
- */
- protected $checkSignOpen = false;//是否校验签名,true校验,false不校验
- public function htmlTest1(){
- View::assign("title","这是标是,从后台来的");
- return view();
- }
- public function createPdfTest1(){
- // echo "test1 begin";
- $pdf=new \TCPDF("P","mm","A4");
- // 设置文档信息
- $pdf->SetCreator('Helloweba');
- $pdf->SetAuthor('yueguangguang');
- $pdf->SetTitle('Welcome to helloweba.com!');
- $pdf->SetSubject('TCPDF Tutorial');
- $pdf->SetKeywords('TCPDF, PDF, PHP');
- // 设置页眉和页脚信息
- $pdf->SetHeaderData('logo.png', 30, 'Helloweba.com', '致力于WEB前端技术在中国的应用',
- 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(15, 27, 15);
- $pdf->SetHeaderMargin(5);
- $pdf->SetFooterMargin(10);
- // 设置分页
- $pdf->SetAutoPageBreak(TRUE, 25);
- // set image scale factor
- $pdf->setImageScale(1.25);
- // set default font subsetting mode
- $pdf->setFontSubsetting(true);
- //设置字体
- $pdf->SetFont('stsongstdlight', '', 14);
- $pdf->AddPage();
- $str1 = '<h1>这是h1</h1><div style="color: #f00;font-size: 14px;">这是红色</div><div style="color: #ddd;font-size: 20px;">这是灰色</div>';
- $pdf->writeHTML($str1, true, false, true, false, '');
- $pdf->AddPage();
- $str1 = '<h1>这是第2页</h1><div style="color: #f00;font-size: 14px;">这是红色</div><div style="color: #ddd;font-size: 20px;">这是灰色</div>';
- $pdf->writeHTML($str1, true, false, true, false, '');
- $pdf->AddPage();
- View::assign("title","这是标是,从后台来的");
- $str1=View::fetch("html_test1");
- $pdf->writeHTML($str1, true, false, true, false, '');
- //输出PDF
- $path=public_path()."/storage/pdf/".date("YmdHis").".pdf";
- $pdf->Output($path, 'F');
- $this->success("","成功");
- }
- }
|