-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_pdf.php
113 lines (108 loc) · 2.85 KB
/
generate_pdf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
require('includes/fpdf.php');
class PDF extends FPDF
{
// Load data
function LoadData($file)
{
// Read file lines
$lines = file($file);
$data = array();
foreach($lines as $line)
$data[] = explode(';',trim($line));
return $data;
}
// Simple table
function BasicTable($header, $data)
{
// Header
// foreach($header as $col)
$this->Cell(120, 8, $header[0], 1, 0, 'C');
$this->Cell(10, 8, $header[1], 1, 0, 'C');
$this->Cell(10, 8, $header[2], 1, 0, 'C');
$this->Cell(10, 8, $header[3], 1, 0, 'C');
$this->Ln();
// Data
foreach($data as $row)
{
$this->Cell(120, 6, $row, 1);
$this->Cell(10, 6, 0, 1);
$this->Cell(10, 6, 0, 1);
$this->Cell(10, 6, 0, 1);
// foreach($row as $col)
// $this->Cell(40,6,$col,1);
$this->Ln();
}
}
// Better table
function ImprovedTable($header, $data)
{
// Column widths
$w = array(40, 35, 40, 45);
// Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C');
$this->Ln();
// Data
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR');
$this->Cell($w[1],6,$row[1],'LR');
$this->Cell($w[2],6,number_format($row[2]),'LR',0,'R');
$this->Cell($w[3],6,number_format($row[3]),'LR',0,'R');
$this->Ln();
}
// Closing line
$this->Cell(array_sum($w),0,'','T');
}
// Colored table
function FancyTable($header, $data)
{
// Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
// Header
$w = array(40, 35, 40, 45);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Ln();
// Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = false;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,number_format($row[2]),'LR',0,'R',$fill);
$this->Cell($w[3],6,number_format($row[3]),'LR',0,'R',$fill);
$this->Ln();
$fill = !$fill;
}
// Closing line
$this->Cell(array_sum($w),0,'','T');
}
}
$pdf = new PDF();
// Column headings
$header = array('Program statement', 'Nr', 'Nmcms', 'Nmcmd');
// Data loading
// $data = $pdf->LoadData('countries.txt');
$pdf->SetFont('Arial','', 8);
$pdf->AddPage();
$pdf->Cell(40, 8, "Displaying the complexity of a program due to all the factors");
$pdf->Ln();
if (isset($_POST["codeLine"])) {
$pdf->BasicTable($header, $_POST["codeLine"]);
}
$pdf->AddPage();
// $pdf->ImprovedTable($header,$data);
// $pdf->AddPage();
// $pdf->FancyTable($header,$data);
$pdf->Output();
?>