-
-
Notifications
You must be signed in to change notification settings - Fork 262
Expand file tree
/
Copy pathE000_overview.php
More file actions
266 lines (221 loc) · 7.87 KB
/
Copy pathE000_overview.php
File metadata and controls
266 lines (221 loc) · 7.87 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
declare(strict_types=1);
/**
* E000_overview.php
*
* @since 2017-05-08
* @category Library
* @package Pdf
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2002-2026 Nicola Asuni - Tecnick.com LTD
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
* @link https://github.com/tecnickcom/tc-lib-pdf
*
* This file is part of tc-lib-pdf software library.
*/
// NOTE: local file reads (images, fonts, attachments) are restricted to an allowlist of
// trusted paths that covers this package tree, so run the examples in place. To read assets
// from other locations, list them in the 'allowedPaths' entry of the fileOptions constructor
// parameter (see E047_remote_resources_security.php).
// NOTE: run make fonts in the project root to generate the dependencies and example fonts.
// autoloader when using Composer
require __DIR__ . '/../vendor/autoload.php';
\define('OUTPUT_FILE', \realpath(__DIR__ . '/../target') . '/example_overview.pdf');
// define fonts directory
\define('K_PATH_FONTS', \realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-font/target/fonts'));
// autoloader when using RPM or DEB package installation
//require ('/usr/share/php/Com/Tecnick/Pdf/autoload.php');
// main TCPDF object
$pdf = new \Com\Tecnick\Pdf\Tcpdf(
unit: \Com\Tecnick\Pdf\Page\Unit::Millimeter,
isunicode: true,
subsetfont: false,
compress: true,
mode: \Com\Tecnick\Pdf\PdfConformance::None,
objEncrypt: null,
);
// ----------
$pdf->setCreator('tc-lib-pdf');
$pdf->setAuthor('Nicola Asuni');
$pdf->setSubject('tc-lib-pdf example: 000');
$pdf->setTitle('tc-lib-pdf Visual Showcase');
$pdf->setKeywords('TCPDF tc-lib-pdf showcase barcode qr svg image transparency gradients');
$pdf->setPDFFilename('000_overview.pdf');
$pdf->setViewerPreferences(['DisplayDocTitle' => true]);
$pdf->enableDefaultPageContent();
// ----------
// Insert fonts
$titleFont = $pdf->font->insert($pdf->pon, 'dejavusans', 'B', 30);
$subtitleFont = $pdf->font->insert($pdf->pon, 'dejavusans', '', 13);
$bodyFont = $pdf->font->insert($pdf->pon, 'dejavusans', '', 10);
$smallFont = $pdf->font->insert($pdf->pon, 'dejavusans', '', 8);
$imgdir = __DIR__ . '/images';
// ----------
// Add first page
$page01 = $pdf->addPage();
$pdf->setBookmark(name: 'Visual showcase', link: '', level: 0, page: -1, posx: 0, posy: 0, fstyle: 'B', color: 'blue');
$pageW = (float) $page01['width'];
$pageH = (float) $page01['height'];
$cardStyle = [
'all' => [
'lineWidth' => 0.35,
'lineCap' => 'butt',
'lineJoin' => 'miter',
'dashArray' => [],
'dashPhase' => 0,
'lineColor' => 'rgb(193,216,242)',
'fillColor' => 'rgb(255,255,255)',
],
];
$lineStyle = [
'all' => [
'lineWidth' => 0.25,
'lineCap' => 'butt',
'lineJoin' => 'miter',
'dashArray' => [],
'dashPhase' => 0,
'lineColor' => 'rgb(147,196,227)',
'fillColor' => 'rgb(147,196,227)',
],
];
$barcodeStyle = [
'lineWidth' => 0,
'lineCap' => 'butt',
'lineJoin' => 'miter',
'dashArray' => [],
'dashPhase' => 0,
'lineColor' => 'black',
'fillColor' => 'black',
];
$textOnDark = $pdf->color->getPdfColor('rgb(244,250,255)');
$textOnLight = $pdf->color->getPdfColor('rgb(22,37,61)');
// Background atmosphere.
$pdf->page->addContent($pdf->graph->getLinearGradient(0, 0, $pageW, $pageH, 'rgb(10,27,60)', 'rgb(0,171,193)', [
0,
0,
1,
1,
]));
$pdf->page->addContent($pdf->graph->getAlpha(0.12));
for ($lineY = -20; $lineY <= 330; $lineY += 12) {
$pdf->page->addContent($pdf->graph->getLine(0, (float) $lineY, $pageW, (float) ($lineY + 95), $lineStyle));
}
$pdf->page->addContent($pdf->graph->getAlpha(0.28));
$pdf->page->addContent($pdf->graph->getCircle(167, 46, 40, 0, 360, 'F', [
'all' => [
'lineWidth' => 0,
'lineCap' => 'butt',
'lineJoin' => 'miter',
'dashArray' => [],
'dashPhase' => 0,
'lineColor' => 'rgb(255,255,255)',
'fillColor' => 'rgb(255,255,255)',
],
]));
$pdf->page->addContent($pdf->graph->getAlpha(1.0));
// Main title block.
$pdf->page->addContent($textOnDark);
$pdf->page->addContent($titleFont['out']);
$pdf->addHTMLCell(
html: '<div style="font-size:30pt; font-weight:bold; color:rgb(244,250,255);">tc-lib-pdf</div>',
posx: 15,
posy: 18,
width: 120,
);
$pdf->page->addContent($subtitleFont['out']);
$pdf->addHTMLCell(
html: '<div style="font-size:13pt; line-height:1.3; color:rgb(244,250,255);">Modern PDF generation in pure PHP: vectors, images, barcodes, and rich page composition.</div>',
posx: 15,
posy: 34,
width: 125,
);
// Left feature card.
$pdf->page->addContent($pdf->graph->getAlpha(0.90));
$pdf->page->addContent($pdf->graph->getRect(12, 56, 89, 137, 'DF', $cardStyle));
$pdf->page->addContent($pdf->graph->getAlpha(1.0));
$pdf->page->addContent($textOnLight);
$pdf->page->addContent($subtitleFont['out']);
$pdf->addHTMLCell(
html: '<div style="font-size:13pt; color:rgb(22,37,61);">Cool Features</div>',
posx: 18,
posy: 64,
width: 72,
);
$pdf->page->addContent($bodyFont['out']);
$features =
'<ul style="font-size:10pt; color:rgb(22,37,61); margin:0; padding-left:12pt;">'
. '<li>Native SVG rendering</li>'
. '<li>JPEG/PNG with transparency</li>'
. '<li>1D/2D barcodes (QR, DataMatrix)</li>'
. '<li>Gradients and vector primitives</li>'
. '<li>HTML/CSS text layout</li>'
. '<li>Digital signatures and PDF/X, PDF/UA support</li>'
. '</ul>';
$pdf->addHTMLCell(html: $features, posx: 18, posy: 74, width: 79);
$logoFile = $imgdir . '/tcpdf_logo.jpg';
if (\is_file($logoFile)) {
$logoId = $pdf->image->add($logoFile);
$pdf->page->addContent($pdf->image->getSetImage($logoId, 153, 10, 40, 13, $pageH));
}
// SVG art panel.
$pdf->page->addContent($pdf->graph->getAlpha(0.92));
$pdf->page->addContent($pdf->graph->getRect(106, 70, 92, 121, 'DF', $cardStyle));
$pdf->page->addContent($pdf->graph->getAlpha(1.0));
$svgFile = $imgdir . '/testsvgblend.svg';
if (\is_file($svgFile)) {
$svgObj = $pdf->addSVG(img: $svgFile, posx: 111, posy: 76, width: 82, height: 108, pageheight: $pageH);
$pdf->page->addContent($pdf->getSetSVG(soid: $svgObj));
}
$pdf->page->addContent($textOnLight);
$pdf->page->addContent($smallFont['out']);
$pdf->addHTMLCell(
html: '<div style="font-size:8pt; text-align:center; color:rgb(22,37,61);">SVG graphic rendered directly into PDF vectors</div>',
posx: 111,
posy: 182,
width: 82,
);
// QR code panel.
$pdf->page->addContent($pdf->graph->getAlpha(0.92));
$pdf->page->addContent($pdf->graph->getRect(12, 198, 186, 76, 'DF', $cardStyle));
$pdf->page->addContent($pdf->graph->getAlpha(1.0));
$pdf->page->addContent($textOnLight);
$pdf->page->addContent($subtitleFont['out']);
$pdf->addHTMLCell(
html: '<div style="font-size:13pt; color:rgb(22,37,61);">Scan to Explore</div>',
posx: 18,
posy: 206,
width: 92,
);
$pdf->page->addContent($bodyFont['out']);
$pdf->addHTMLCell(
html: '<div style="font-size:10pt; line-height:1.25; color:rgb(22,37,61);">This QR code points to the official TCPDF project page:</div>',
posx: 18,
posy: 216,
width: 118,
);
$pdf->addHTMLCell(
html: '<div style="font-size:10pt; color:rgb(22,37,61);"><a href="https://tcpdf.org">https://tcpdf.org</a></div>',
posx: 18,
posy: 228,
width: 118,
);
$pdf->page->addContent($pdf->getBarcode(
type: 'QRCODE,H',
code: 'https://tcpdf.org',
posx: 145,
posy: 206,
width: 45,
height: 45,
padding: [0, 0, 0, 0],
style: $barcodeStyle,
));
// =============================================================
// ----------
// get PDF document as raw string
$rawpdf = $pdf->getOutPDFString();
// ----------
// Various output modes:
//$pdf->savePDF(\dirname(__DIR__).'/target', $rawpdf);
$pdf->renderPDF(rawpdf: $rawpdf);
//$pdf->downloadPDF($rawpdf);
//echo $pdf->getMIMEAttachmentPDF($rawpdf);