日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

Thinkphp 整合tcpdf

發布時間:2023/12/10 php 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Thinkphp 整合tcpdf 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

網上查了些關于tcpdf 使用教程,整合到TP的話,會有些小問題,由于基礎還不是很扎實,花了點時間終于整合OK了。下面介紹步驟:

環境:

  TP版本:TP3.2.2

  tcpdf:tcpdf_6_2_3

1. 將tcpdf_6_2_3.zip解壓在Web root目錄下面,把examples文件夾下面的tcpdf_include.php文件拷貝到tcpdf文件夾下面,再把tcpdf/config/tcpdf_config.php內容替換成tcpdf/examples/config/tcpdf_config_alt.php中的內容

  這里要注意的是:tcp_include.php中?$tcpdf_include_dirs數組要多添加一行:“realpath('./').'/tcpdf/tcpdf.php',”

2. 新建test.php

  

<?php // Include the main TCPDF library (search for installation path). require_once('./tcpdf/tcpdf_include.php');// create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);// set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Nicola Asuni'); $pdf->SetTitle('TCPDF Example'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide');// set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' wisvalley', PDF_HEADER_STRING);// set header and footer fonts $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));// set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);// set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);// set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);// set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);// set some language-dependent strings (optional) if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {require_once(dirname(__FILE__).'/lang/eng.php');$pdf->setLanguageArray($l); }// ---------------------------------------------------------// set font //$pdf->SetFont('helvetica', '', 20); $pdf->SetFont('stsongstdlight', '', 20); // add a page $pdf->AddPage();$txt = 'your content'; $pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0); $pdf->Output('/var/www/example_038.pdf', 'I');//瀏覽器預覽 //$pdf->Output('example_038.pdf', 'F');//存儲文件 //$pdf->Output('example_038.pdf', 'D');//下載文件

這樣就可以了。下面說下我碰到的幾個問題:

  1.我把這些代碼拷貝到TP控制器的某個方法里面報錯:Class 'Home\Controller\TCPDF' not found

    解答:$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

        改成$pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

        對于tp3.2引入了命名空間,這個‘\’很重要

?

  2.TCPDF ERROR:?Unable to create output file: example_038.pdf

    解答:$pdf->Output('/var/www/example_038.pdf', 'I');路徑要為據對路徑。

?

轉載于:https://www.cnblogs.com/liushiyong1/p/4201117.html

總結

以上是生活随笔為你收集整理的Thinkphp 整合tcpdf的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。