naitsirch tcpdf extension
v1.2.0
TCPDF เป็นไลบรารี PHP เพื่อสร้างเอกสาร PDF มันเป็นคุณสมบัติที่อุดมไปด้วย แต่ไม่ง่ายที่จะใช้
ห้องสมุดนี้สร้างขึ้นที่ด้านบนของไลบรารี TCPDF ในสถานะปัจจุบันมีเพียง API อัจฉริยะเพื่อ สร้างตารางอย่างสะดวกสบาย
ที่เก็บนี้ถูกทอดทิ้งและไม่ควรใช้อีกต่อไป โปรดเปลี่ยนจาก naitsirch/tcpdf-extension เป็น stollr/tcpdf-extension ที่เข้ากันได้
วิธีที่ง่ายที่สุดในการใช้ไลบรารีนี้คือการติดตั้งผ่านนักแต่งเพลง
เพิ่มสิ่งนี้ลงในนักแต่งเพลงของโครงการของคุณ json:
{
"require" : {
"naitsirch/tcpdf-extension" : " dev-master "
}
}ก่อนอื่นคุณต้องสร้างอินสแตนซ์ของ TCPDF
use TCPDF ;
$ pdf = new TCPDF ( ' P ' , ' mm ' , ' A4 ' , true , ' UTF-8 ' , false );
$ pdf -> SetTitle ( ' My PDF file ' );
$ pdf -> SetMargins ( 20 , 20 , 20 );
$ pdf -> SetPrintHeader ( false );
$ pdf -> SetPrintFooter ( false );
$ pdf -> SetAutoPageBreak ( true , 9 );
$ pdf -> SetFont ( ' dejavusans ' , '' , 10 );โปรดดูเอกสารของคลาส TCPDF หากคุณไม่คุ้นเคย
ในขั้นตอนถัดไปคุณสามารถสร้างตาราง
use Tcpdf Extension Table Table ;
$ pdf -> AddPage (); // add a new page to the document
$ table = new Table ( $ pdf );
$ table
-> newRow ()
-> newCell ()
-> setText ( ' Last Name ' )
-> setFontWeight ( ' bold ' )
-> end ()
-> newCell ()
-> setText ( ' First Name ' )
-> setFontWeight ( ' bold ' )
-> end ()
-> newCell ()
-> setText ( ' DOB ' )
-> setFontWeight ( ' bold ' )
-> end ()
-> newCell ()
-> setText ( ' Email ' )
-> setFontWeight ( ' bold ' )
-> end ()
-> end ()
-> newRow ()
-> newCell ( ' Foo ' )-> end ()
-> newCell ( ' John ' )-> end ()
-> newCell ( ' 1956-04-14 ' )-> end ()
-> newCell ( ' [email protected] ' )-> end ()
-> end ()
;
$ table -> end (); // this prints the table to the PDF. Don't forget!รหัสด้านบนแสดงวิธีสร้างตารางที่ง่ายมาก แต่คุณสามารถปรับแต่งเซลล์ตารางในรูปแบบที่แตกต่างกัน:
$ table
-> newRow ()
-> newCell ( ' Last Name ' ) // you can set the cell content like this
-> setText ( ' Override Text ' ) // or like this
-> setFontWeight ( ' bold ' ) // set font weight 'bold' or 'normal'
-> setAlign ( ' L ' ) // text alignment ('L', 'C', 'R' or 'J')
-> setVerticalAlign ( ' top ' ) // vertical alignment ('top', 'bottom' or 'middle')
-> setBorder ( 1 ) // border format (like in TCPDF::MultiCell)
-> setRowspan ( 1 ) // rowspan like in HTML
-> setColspan ( 2 ) // colspan like in HTML
-> setFontSize ( 10 ) // unit for font size is same as defined in TCPDF
-> setMinHeight ( 10 ) // defining min-height of the cell like in CSS
-> setPadding ( 2 , 4 ) // setting cell padding (inner margin) like in CSS
-> setPadding ( 2 , 4 , 5 , 6 ) // or like this
-> setWidth ( 125 ) // unit for width is same as defined in TCPDF
-> end ()กำหนดสีพื้นหลัง:
$ table
-> newRow ()
-> newCell ( ' Last Name ' )
-> setBackgroundColor ( ' #ff4400 ' ) // hexadecimal RGB color code
->setBackgroundColor( array ( 250 , 80 , 10 ) // decimal RGB color array
-> end ()
-> end ()เป็นไปได้ที่จะกำหนดภาพพื้นหลังสำหรับแต่ละเซลล์ตาราง
$ table
-> newRow ()
-> newCell ( ' Last Name ' )
-> setBackgroundDpi ( 300 ) // define the resolution for the printing
-> setBackgroundImage ( ' /path/to/my/image.png ' ) // pass the path to your image
-> setBackgroundImage ( $ binaryImageString ) // or pass the binary file content of your image
-> end ()
-> end ()