欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

thinkPHP框架整合tcpdf插件操作示例

 更新時(shí)間:2018年08月07日 12:08:19   作者:井底_之蛙  
這篇文章主要介紹了thinkPHP框架整合tcpdf插件操作,結(jié)合實(shí)例形式較為詳細(xì)的分析了thinkPHP框架整合tcpdf插件的具體步驟、相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了thinkPHP框架整合tcpdf插件操作。分享給大家供大家參考,具體如下:

網(wǎng)上查了些關(guān)于tcpdf 使用教程,整合到TP的話,會(huì)有些小問題,由于基礎(chǔ)還不是很扎實(shí),花了點(diǎn)時(shí)間終于整合OK了。下面介紹步驟:

環(huán)境:

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內(nèi)容替換成tcpdf/examples/config/tcpdf_config_alt.php中的內(nèi)容

這里要注意的是:tcp_include.php$tcpdf_include_dirs數(shù)組要多添加一行:“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');//瀏覽器預(yù)覽
//$pdf->Output('example_038.pdf', 'F');//存儲文件
//$pdf->Output('example_038.pdf', 'D');//下載文件

這樣就可以了。

下面說下我碰到的幾個(gè)問題:

1.我把這些代碼拷貝到TP控制器的某個(gè)方法里面報(bào)錯(cuò):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引入了命名空間,這個(gè)‘\'很重要

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

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

附:tcpdf插件點(diǎn)擊此處本站下載。

更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術(shù)總結(jié)》。

希望本文所述對大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論