1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace app\index\controller;
- use think\facade\View;
- class Pdf extends Base
- {
-
-
- protected $checkSignOpen = false;
- public function htmlTest1(){
- View::assign("title","这是标是,从后台来的");
- return view();
- }
- public function createPdfTest1(){
- $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);
- $pdf->setImageScale(1.25);
- $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, '');
-
- $path=public_path()."/storage/pdf/".date("YmdHis").".pdf";
- $pdf->Output($path, 'F');
- $this->success("","成功");
- }
- }
|