1
|
<?php
|
2
|
/*error_reporting(E_ALL);
|
3
|
ini_set('display_errors', 1);
|
4
|
/**
|
5
|
* Pdf Advanced Table - Example
|
6
|
* Copyright (c), Andrei Bintintan, http://www.interpid.eu
|
7
|
*/
|
8
|
|
9
|
// include the pdf factory
|
10
|
include_once ( "/tfpdf_table/pdfFactory.php" );
|
11
|
|
12
|
// Include the Advanced Table Class
|
13
|
include_once ( "/tfpdf_table/classes/pdftable.php" );
|
14
|
|
15
|
/**
|
16
|
* Include my Custom PDF class This is required only to overwrite the header
|
17
|
*/
|
18
|
include_once ( "/tfpdf_table/mypdf-table.php" );
|
19
|
|
20
|
$factory = new pdfFactory();
|
21
|
|
22
|
// create new PDF document
|
23
|
$oPdf = new myPdfTable();
|
24
|
$factory->initPdfObject( $oPdf );
|
25
|
|
26
|
//$oPdf->drawMarginLines();
|
27
|
/**
|
28
|
* Create the pdf Table object
|
29
|
* Alternative you can use the Singleton Instance
|
30
|
*
|
31
|
* @example : $oTable = PdfTable::getInstance($oPdf);
|
32
|
*/
|
33
|
|
34
|
|
35
|
$oPdf->Cell(0,10,'BUG',0,0,'L');
|
36
|
$oPdf->Ln(10);
|
37
|
|
38
|
$oTable = new PdfTable( $oPdf );
|
39
|
|
40
|
/**
|
41
|
* Set the tag styles
|
42
|
*/
|
43
|
$oTable->setStyle( "p", $oPdf->getDefaultFontName(), "", 10, "130,0,30" );
|
44
|
$oTable->setStyle( "b", $oPdf->getDefaultFontName(), "", 9, "80,80,260" );
|
45
|
$oTable->setStyle( "h1", $oPdf->getDefaultFontName(), "", 10, "0,151,200" );
|
46
|
$oTable->setStyle( "bi", $oPdf->getDefaultFontName(), "BI", 12, "0,0,120" );
|
47
|
$oTable->setStyle( "size", $oPdf->getDefaultFontName(), "BI", 13, "0,0,120" );
|
48
|
|
49
|
//default text color
|
50
|
$oPdf->SetTextColor( 118, 0, 3 );
|
51
|
|
52
|
//create an advanced multicell
|
53
|
$oMulticell = PdfMulticell::getInstance( $oPdf );
|
54
|
$oMulticell->setStyle( "s1", $oPdf->getDefaultFontName(), "", 8, "118,0,3" );
|
55
|
$oMulticell->setStyle( "s2", $oPdf->getDefaultFontName(), "", 6, "0,49,159" );
|
56
|
$oMulticell->multiCell( 100, 4, "<s1>Example - Override Default Configuration Values</s1>", 0 );
|
57
|
|
58
|
$nColumns = 3;
|
59
|
|
60
|
$aCustomConfiguration = array(
|
61
|
'TABLE' => array(
|
62
|
'TABLE_ALIGN' => 'L', //left align
|
63
|
'BORDER_COLOR' => array( 0, 0, 0 ), //border color
|
64
|
'BORDER_SIZE' => '0.5', //border size
|
65
|
),
|
66
|
|
67
|
'HEADER' => array(
|
68
|
'TEXT_COLOR' => array( 25, 60, 170 ), //text color
|
69
|
'TEXT_SIZE' => 9, //font size
|
70
|
'LINE_SIZE' => 6, //line size for one row
|
71
|
'BACKGROUND_COLOR' => array( 182, 240, 0 ), //background color
|
72
|
'BORDER_SIZE' => 0.5, //border size
|
73
|
'BORDER_TYPE' => 'B', //border type, can be: 0, 1 or a combination of: "LRTB"
|
74
|
'BORDER_COLOR' => array( 0, 0, 0 ), //border color
|
75
|
),
|
76
|
|
77
|
'ROW' => array(
|
78
|
'TEXT_COLOR' => array( 225, 20, 0 ), //text color
|
79
|
'TEXT_SIZE' => 6, //font size
|
80
|
'BACKGROUND_COLOR' => array( 232, 255, 209 ), //background color
|
81
|
'BORDER_COLOR' => array( 150, 255, 56 ), //border color
|
82
|
),
|
83
|
);
|
84
|
|
85
|
//Initialize the table class, 3 columns
|
86
|
$oTable->initialize( array( 40, 50, 30 ), $aCustomConfiguration );
|
87
|
|
88
|
$aHeader = array();
|
89
|
|
90
|
//Table Header
|
91
|
for ( $i = 0; $i < $nColumns; $i++ )
|
92
|
{
|
93
|
$aHeader[ $i ][ 'TEXT' ] = "Header #" . ( $i + 1 );
|
94
|
}
|
95
|
|
96
|
//add the header
|
97
|
$oTable->addHeader( $aHeader );
|
98
|
|
99
|
for ( $j = 1; $j < 105; $j++ )
|
100
|
{
|
101
|
$aRow = Array();
|
102
|
$aRow[ 0 ][ 'TEXT' ] = "Line $j Text 1"; //text for column 0
|
103
|
$aRow[ 1 ][ 'TEXT' ] = "Line $j Text 2"; //text for column 1
|
104
|
$aRow[ 2 ][ 'TEXT' ] = "Line $j Text 3"; //text for column 2
|
105
|
|
106
|
|
107
|
//override some settings for row 2
|
108
|
if ( 2 == $j )
|
109
|
{
|
110
|
$aRow[ 1 ][ 'TEXT_ALIGN' ] = 'L';
|
111
|
$aRow[ 1 ][ 'TEXT' ] = "<p>This is a <b>Multicell</b></p>";
|
112
|
}
|
113
|
|
114
|
//add the row
|
115
|
$oTable->addRow( $aRow );
|
116
|
}
|
117
|
|
118
|
//close the table
|
119
|
$oTable->close();
|
120
|
|
121
|
//send the pdf to the browser
|
122
|
$oPdf->Output();
|