TCPDF使用說明

2021-08-03 11:32:34 字數 3770 閱讀 8259

呼叫tcpdf檔案

require_once('tcpdf.php');
設定時區,否則會導致報錯

date_default_timezone_set('asia/shanghai');
例項化tcpdf

頁面方向(p =肖像,l =景觀)、測量(mm)、頁面格式

$pdf = new tcpdf('p', 'mm', 'a4', true, 'utf-8', false);
設定文件資訊

$pdf->setcreator('helloweba');

$pdf->setauthor('yueguangguang');

$pdf->settitle('welcome to helloweba.com!');

$pdf->setsubject('tcpdf tutorial');

$pdf->setkeywords('tcpdf, pdf, php');

擴充套件,自定義頁首頁尾

設定pdf背景

$image_file = k_path_images.'bkground.png';

$this->image($image_file, 0, 0, 210, 15, '', '', '', false, 300, '', false, false, 0);

設定背景顏色(需要注意,只能設定乙個)

$this->rect(0,0,210,297,'f','',$fill_color = array(255, 255, 255));
設定字型(droidsansfallback該字型為匯入字型,支援中文)

$this->setfont('droidsansfallback', 'b', 13);
設定文字顏色

$this->settextcolor(171,171,171);
設定表內內容距離邊框的距離。分別左、上、右、下。

$this->setcellpaddings(15, 10, 5, 0);

$this->setcellmargins(0, 1, 0, 0);//

$this->cell(180, 15, '測試', 0, true, 'l', 0, '', 0, true, 'm', 'm');

$this->setfont('droidsansfallback', 'b', 8);

注意如想在不同位置設定文字,可多次使用setcellpaddings()不會產生衝突。

設定表內內容距離邊框的距離。分別左、上、右、下。

$this->setcellpaddings(13, 10, 5, 2);
設定是否列印頁首頁尾,即去掉預設橫線

$pdf->setprintheader(true); //設定列印頁首

$pdf->setprintfooter(false); //設定列印頁尾

設定預設頁首頁尾相關引數

$pdf->setheaderdata(pdf_header_logo, pdf_header_logo_width, pdf_header_title.' 061', pdf_header_string);

設定頁首頁尾字型

$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);

$pdf->setheadermargin(pdf_margin_header);

$pdf->setfootermargin(pdf_margin_footer);

設定pdf頁面邊距(margin)

$pdf->setmargins(1, 15, 1);//左、右、上

$pdf->setautopagebreak(true, 15);//下

設定縮放比例

$pdf->setimagescale(pdf_image_scale_ratio);
新增乙個頁面包含結束符

$pdf->addpage();

$pdf->lastpage();

設定行距

$pdf->ln(4);
如何巢狀html的三種方式

此方法渲染html邊框頂格

$pdf->writehtml($html, true, false, true, false, '');
原型為 writehtml($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
第乙個引數為html格式的字串;第三個引數設定是否填充背景色,值為false(不填充)或true(填充);
此方法渲染html會產生一定間距

$pdf->writehtmlcell(80, '', '', $y, $left_column, 1, 0, 1, true, 'j',  true);
原型:writehtmlcell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=false,  $reseth=true, $align='', $autopadding=true),
引數可對照multicell(),分別為寬度,高 度,x座標,y座標,內容,是否右邊框,與下乙個單元格的相對為位置,是否填充背景色,是否重置高度,文字對齊方式,是否自動…
此方法渲染html會居中效果,注意將$ishtml設定為true

$pdf->multicell(0, 5, $html, $border=0, $align='c',$fill=false, $ln=1, $x='', $y='',  $reseth=true, $stretch=0,$ishtml=true,$autopadding=true);
設定獲取xy座標

$pdf->sety()/gety()
設定直線,注意第二個引數和第四個引數保持一致時才為水平直線

$linestyle = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(143,195,226));

$pdf->line(6, 32, 200, 32, $linestyle);

設定左邊距、右邊距

$pdf->setleftmargin(0);

$pdf->setrightmargin(0);

$pdf->output('report_new.pdf', 'i');

使用說明 附註工具使用說明

附註工具使用說明 附註工具用途 附註工具主要用於更新利用word附註應用程式生成的帶域 的附註,該工具在word右鍵 更新鏈結 的基礎上進行了優化,故在使用時,不能再利用word右鍵 更新鏈結 而要用本工具的 更新當前鏈結 或 更新所有鏈結 使用說明 一 更換路徑 當利用word附註應用程式生成帶域...

使用說明 農用遮光網使用說明

農用遮光網使用說明 建築防塵網購買方 建築施工企業 在購買建築防塵網時,應該對 作出比較,可以分辨品牌 型號,且購買時應該在一定程度上了解信譽良莠。建築防塵網購買方 市場售賣方 在選購建築防塵網時,可以把 作為基礎,好的 可以用來彌補信譽不足,而差的 則需要按照你的服務收費。農用遮光網使用說明 用途...

Hibernate tools 使用說明

05年的8月份第一次接觸hibernate tools,使用起來感覺還不錯,但也沒有深入研究,後來由於一直在做乙個專案,再後來用了一陣myeclipse,現在換了公司,使用wtp all in one eclipse的乙個版本 生成domain的時候使用了hibernate tools,發現都不知怎...