-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.php
More file actions
79 lines (61 loc) · 2.53 KB
/
basic.php
File metadata and controls
79 lines (61 loc) · 2.53 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
<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use TinyPdf\TinyPdf;
use TinyPdf\TextOptions;
use TinyPdf\TextAlign;
use TinyPdf\LinkOptions;
echo "Creating basic PDF with text and shapes...\n";
$pdf = TinyPdf::create();
$pdf->page(function ($ctx) {
// Title
$ctx->text('TinyPDF-PHP Demo', 50, 720, 32, new TextOptions(color: '#2c3e50'));
// Subtitle with alignment
$ctx->text(
'A minimal PDF creation library',
50,
680,
16,
new TextOptions(align: TextAlign::LEFT, color: '#7f8c8d')
);
// Colored rectangle divider
$ctx->rect(50, 620, 500, 2, '#3498db');
// Paragraph
$text = 'This PDF was generated using TinyPDF-PHP, a strongly-typed, zero-dependency PDF library for PHP 8.0+.';
$ctx->text($text, 50, 580, 12, new TextOptions(color: '#34495e'));
// Colored boxes demonstration
$colors = ['#e74c3c', '#3498db', '#2ecc71', '#f39c12', '#9b59b6'];
$x = 50;
foreach ($colors as $color) {
$ctx->rect($x, 500, 90, 50, $color);
$x += 100;
}
// Lines with different widths
$ctx->line(50, 470, 550, 470, '#000000', 1);
$ctx->line(50, 460, 550, 460, '#e74c3c', 2);
$ctx->line(50, 448, 550, 448, '#3498db', 3);
// Text alignment examples
$ctx->rect(50, 340, 500, 80, '#f8f9fa');
$ctx->text('Left Aligned', 50, 400, 12, new TextOptions(align: TextAlign::LEFT, width: 500));
$ctx->text('Center Aligned', 50, 380, 12, new TextOptions(align: TextAlign::CENTER, width: 500));
$ctx->text('Right Aligned', 50, 360, 12, new TextOptions(align: TextAlign::RIGHT, width: 500));
// Clickable links
$ctx->text('Clickable Links:', 50, 300, 14, new TextOptions(color: '#2c3e50'));
$ctx->text('GitHub Repository', 50, 270, 12, new TextOptions(color: '#0066cc'));
$ctx->link('https://github.com/kallefrombosnia/tinypdf-php', 50, 265, 115, 20, new LinkOptions(underline: '#0066cc'));
$ctx->text('Sponsored by Flowout', 200, 270, 12, new TextOptions(color: '#95a5a6'));
$ctx->link('https://www.flowout.com/', 200, 265, 128, 20);
// Footer
$ctx->text('Page 1', 50, 50, 10, new TextOptions(color: '#95a5a6'));
$ctx->text(
'Generated with TinyPDF-PHP',
50,
50,
10,
new TextOptions(align: TextAlign::RIGHT, width: 500, color: '#95a5a6')
);
});
$pdfContent = $pdf->build();
file_put_contents(__DIR__ . '/output.pdf', $pdfContent);
echo "Basic PDF created: examples/basic/output.pdf\n";
echo "File size: " . strlen($pdfContent) . " bytes\n";