Project

General

Profile

Task #1731 » example-table-1731.php

Andrei Bintintan, 02/10/2019 09:40 PM

 
1
<?php
2
/**
3
 * Pdf Advanced Table - Example
4
 * Copyright (c), Interpid, http://www.interpid.eu
5
 */
6

    
7
require_once __DIR__ . "/../autoload.php";
8

    
9
use Interpid\PdfLib\Multicell;
10
use Interpid\PdfExamples\PdfFactory;
11
use Interpid\PdfLib\Table;
12

    
13
$factory = new PdfFactory();
14

    
15
//get the PDF object
16
$pdf = PdfFactory::newPdf('table');
17

    
18
$table = new Table($pdf);
19

    
20

    
21
$table->SetStyle("red", $pdf->getDefaultFontName(), "", 9, "255,0,0");
22
$table->SetStyle("blue", $pdf->getDefaultFontName(), "", 9, "0,0,255");
23
// $oTable->SetStyle( "red", $pdf->getDefaultFontName(), B=Bold I=Italic U=Underline, Fontsize, Color array );
24

    
25
$table->initialize(array(24, 78, 78));
26

    
27
$aRow = array();
28

    
29
$count = 30;
30

    
31
for ($i = 1; $i < $count + 1; $i++) {
32

    
33
    $aRow = array();
34
    $aRow[ 0 ] = array(
35
        'TEXT' => "SELER INfo",
36
        'TEXT_TYPE' => 'B',
37
        'PADDING_LEFT' => 2,
38
        'PADDING_RIGHT' => 2,
39
        'PADDING_TOP' => 5,
40
        'PADDING_BOTTOM' => 5,
41
        'VERTICAL_ALIGN' => 'T',
42
        'TEXT_ALIGN' => 'L',
43
        'TEXT_SIZE' => 7,
44
        'BORDER_TYPE' => 'LRTB'
45
    );
46
    $aRow[ 1 ] = array(
47
        'TEXT' => str_repeat("Reset Picture count for this sub element\n", rand(1, 10)),
48
//        'TEXT_COLOR' => $textcolour,
49
        'TEXT_ALIGN' => 'L',
50
        'TEXT_SIZE' => 9,
51
        'PADDING_LEFT' => 2,
52
        'PADDING_RIGHT' => 2,
53
        'PADDING_TOP' => 5,
54
        'PADDING_BOTTOM' => 5,
55
        'BORDER_TYPE' => 'LRTB',
56
        'COLSPAN' => 2,
57
    );
58
    $table->addRow($aRow);
59

    
60
// Any pictures now ?
61
    $subelecnt = 0;                            // Reset Picture count for this sub element
62
    for ($j = 0; $j < 2; $j++) {            // Loop round the number of pix found for the whole of section 2 - could be none but a max of 2.
63
        if ($i > 2) {                    // if chars 3 and 4 of the pic filename equals the sub section 1-12 then insert the picture
64

    
65
            $subelecnt = $subelecnt + 1;        // add 1 to element pix count = max of two allowed
66

    
67
            if (true) {                // CH16/3 - changed from max of 2 to 12 - If picture 1 - 12 then allow thru - max of 12 allowed
68

    
69
                $aRow = array();
70
                $aRow[ 0 ] = array(
71
                    'ROWSPAN' => 2,
72
                    'TEXT' => ' ',
73
                    'BORDER_TYPE' => 'LRB',
74
                );  // CHXMAS17 - Added ROWSPAN to cure picture and caption on same page
75
//				$aRow[ 0 ] = array( 'TEXT' => ' ','BORDER_TYPE' => 'LR',);
76

    
77
                $aRow[ 1 ] = array(
78
                    'TYPE' => 'IMAGE',
79
                    'FILE' => PDF_RESOURCES_IMAGES . '/dice.jpg',
80
                    'WIDTH' => 40,
81
                    'BORDER_TYPE' => 'LRB',
82
                    'ALIGN' => 'C',
83
                    'COLSPAN' => 2
84
                );
85
                $table->addRow($aRow);
86

    
87
                $aRow = array();
88
                $aRow[ 0 ] = array('TEXT' => ' ', 'BORDER_TYPE' => 'LRB',);
89
                $aRow[ 1 ] = array(
90
                    'TEXT' => "fooo-bar",
91
                    'TEXT_SIZE' => 8,
92
                    'BORDER_TYPE' => 'LR',
93
                    'ALIGN' => 'C',
94
                    'COLSPAN' => 2,
95
                );
96
                $table->addRow($aRow);
97

    
98
            }
99
        }
100
    }
101
}
102

    
103
$table->close();
104

    
105
//send the pdf to the browser
106
$pdf->Output();
(6-6/6)