TCPDF_使用PHP生成pdf

由于之前工作需要每月份生成一份pdf样式的账单给客户,于是百度了一番,决定使用TCPDF工具,网上中文文档少的可怜,在此记录下自己写的部分代码。
项目结构如下:(有需求的联系博主)
TCPDF_使用PHP生成pdf_第1张图片
入口调用文件为pdf.php,代码如下:

SetCreator('Helloweba'); 
    $pdf->SetAuthor('yueguangguang'); */
    /*$pdf->SetTitle('Welcome to shewentm.com!'); 
    $pdf->SetSubject('TCPDF Tutorial'); 
    $pdf->SetKeywords('TCPDF, PDF, PHP'); */
    
    // 设置页眉和页脚信息 
    $pdf->SetHeaderData('', 15, '','BEIJING SHENWEN INTELLECTUAL PROPERTY MANAGEMENT CO.LTD.
    Suite 1607A Dahangjiye Mansion     Tel:86-10-8268 5045 Fax:86-10-8268 4574
    No.33 North Road Renda,Haidian District,Beijing 10080,PR China',  
          array(0,0,0), array(0,64,128)); 
    $pdf->setPrintFooter(false);
    //$pdf->setFooterData('', 15, '','yejiao',  array(0,0,0), array(0,64,128)); 
     
    // 设置页眉和页脚字体 
    $pdf->setHeaderFont(Array('cid0kr', '', '12')); 
    $pdf->setFooterFont(Array('cid0kr', '', '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('cid0kr', '', 13); 
    //$pdf->SetFont('cid0jp', '', 13); 
    //$pdf->SetFont('times', '', 13); 
     
    $pdf->AddPage(); 
     
    //设置左边距
    $pdf->SetLeftMargin(15); 
    $date = date('Y-m-d');    //生成账单日期
    $fill = '                                                                                                     ';
    $contents = "

                                                      INVOICE

$fill No.$OrderNo

$fill $date

$AddressInfo

Re:Trademark Service in China

    Total Cost : $ $Total(Please access SHEWEN to check expense details)

    Unit in $CName : $Currency $Payables

TOTAL:

       $EngAmount



Please pay this bill within 15 days by wire transfer to our account as follows:
Beneficiary's bank:HUA XIA BANK H.O
SWIFT BIC:HXBKCNBJ030
Beneficiary:BEIJING SHEWEN INTELLECTUAL PROPERTY MANAGEMENT CO.LTD
A/C No:10277000000660845"; $pdf->Image('logo.jpg',0,170,200); //显示图片 $pdf->writeHTML($contents); $name = $OrderNo . '.pdf'; $path = $PDFpath . $name; //在浏览器打开PDF $pdf->Output($path, 'I'); //生成PDF文件 //$res = $pdf->Output($name, 'S'); //file_put_contents($path, $res); }

需要注意的是,因为字体问题,有很多字体不支持特殊符号。博主在试了很多字体文件,最终找到droidsansfallback字体支持特殊符号(并不确定支持所有特殊符号)。
QQ截图20200305110131.png

你可能感兴趣的:(php)