-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.php
More file actions
144 lines (109 loc) · 4.74 KB
/
Copy pathreport.php
File metadata and controls
144 lines (109 loc) · 4.74 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use TinyPdf\TinyPdf;
use TinyPdf\TextOptions;
use TinyPdf\TextAlign;
echo "Creating progress report PDF...\n";
$pdf = TinyPdf::create();
$pdf->page(612, 792, function ($ctx) {
$margin = 50;
$pageWidth = 612;
$contentWidth = $pageWidth - $margin * 2;
// Header background
$ctx->rect(0, 730, $pageWidth, 62, '#1a4d7a');
// Title
$ctx->text('Software Development Progress Report', $margin, 750, 18, new TextOptions(color: '#ffffff'));
// Date in header
$ctx->text('Dec 12, 2018', $margin, 750, 10, new TextOptions(
align: TextAlign::RIGHT,
width: $contentWidth,
color: '#ffffff'
));
// Info section labels and values
$y = 700;
$labelX = $margin;
$valueX = $margin + 150;
$infoItems = [
['Developer\'s Full Name', 'John R. Hashimoto'],
['E-mail', 'john@developersreport.com'],
['Date/Time Stamp', 'Wednesday, December 26, 2018 15:40'],
['Target Date', 'Saturday, December 29, 2018'],
['Progress of work (%)', '70 / 100'],
];
foreach ($infoItems as $item) {
$ctx->text($item[0], $labelX, $y, 10, new TextOptions(color: '#333333'));
$ctx->text($item[1], $valueX, $y, 10, new TextOptions(color: '#000000'));
$y -= 18;
}
// Separator line
$y -= 10;
$ctx->line($margin, $y, $pageWidth - $margin, $y, '#cccccc', 1);
// Content sections
$y -= 25;
// Section 1: How much of the work is completed?
$ctx->text('How much of the work is completed?', $margin, $y, 12, new TextOptions(color: '#1a4d7a'));
$y -= 18;
$paragraph1 = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.';
$lines1 = wrapText($paragraph1, 10, $contentWidth);
foreach ($lines1 as $line) {
$ctx->text($line, $margin, $y, 10, new TextOptions(color: '#333333'));
$y -= 14;
}
$y -= 10;
// Section 2: Remaining Work Items
$ctx->text('Remaining Work Items', $margin, $y, 12, new TextOptions(color: '#1a4d7a'));
$y -= 18;
$paragraph2 = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.';
$lines2 = wrapText($paragraph2, 10, $contentWidth);
foreach ($lines2 as $line) {
$ctx->text($line, $margin, $y, 10, new TextOptions(color: '#333333'));
$y -= 14;
}
$y -= 10;
// Section 3: Experienced Challenges
$ctx->text('Experienced Challenges', $margin, $y, 12, new TextOptions(color: '#1a4d7a'));
$y -= 18;
$paragraph3 = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.';
$lines3 = wrapText($paragraph3, 10, $contentWidth);
foreach ($lines3 as $line) {
$ctx->text($line, $margin, $y, 10, new TextOptions(color: '#333333'));
$y -= 14;
}
$y -= 10;
// Section 4: How were the challenges handled?
$ctx->text('How were the challenges handled?', $margin, $y, 12, new TextOptions(color: '#1a4d7a'));
$y -= 18;
$paragraph4 = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.';
$lines4 = wrapText($paragraph4, 10, $contentWidth);
foreach ($lines4 as $line) {
$ctx->text($line, $margin, $y, 10, new TextOptions(color: '#333333'));
$y -= 14;
}
});
$pdfContent = $pdf->build();
file_put_contents(__DIR__ . '/output.pdf', $pdfContent);
echo "Progress report PDF created: examples/report/output.pdf\n";
echo "File size: " . strlen($pdfContent) . " bytes\n";
// Helper function to wrap text
function wrapText(string $text, float $size, float $maxWidth): array
{
$words = explode(' ', $text);
$lines = [];
$line = '';
foreach ($words as $word) {
$test = $line === '' ? $word : $line . ' ' . $word;
if (TinyPdf::measureText($test, $size) <= $maxWidth) {
$line = $test;
} else {
if ($line !== '') {
$lines[] = $line;
}
$line = $word;
}
}
if ($line !== '') {
$lines[] = $line;
}
return $lines !== [] ? $lines : [''];
}