forked from spipu/html2pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.php
More file actions
77 lines (66 loc) · 1.77 KB
/
Button.php
File metadata and controls
77 lines (66 loc) · 1.77 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
<?php
namespace Spipu\Html2Pdf\Tag\Html;
use Spipu\Html2Pdf\Tag\AbstractTag;
/**
* Button Tag class
*/
class Button extends AbstractTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'button';
}
/**
* @inheritdoc
*/
public function open($properties)
{
$styles = $this->getStyleFromProperties($properties);
// Set default button styling if not specified
if (!isset($styles['background'])) {
$styles['background'] = '#f0f0f0';
}
if (!isset($styles['border'])) {
$styles['border'] = '1px solid #ccc';
}
if (!isset($styles['padding'])) {
$styles['padding'] = '5px 10px';
}
// Add custom class if provided
if (isset($properties['class'])) {
$this->parsingCss->analyse('button.' . $properties['class']);
}
// Handle button type
$type = isset($properties['type']) ? $properties['type'] : 'button';
// Create button container with proper styling
$this->pdf->setStyle($styles);
return true;
}
/**
* @inheritdoc
*/
public function close($properties)
{
// Reset styles after button closure
$this->pdf->resetStyle();
return true;
}
/**
* @inheritdoc
*/
protected function getStyleFromProperties($properties)
{
$styles = [];
// Handle standard CSS properties
$cssProperties = ['width', 'height', 'background', 'color', 'border', 'padding', 'margin', 'font-size'];
foreach ($cssProperties as $prop) {
if (isset($properties[$prop])) {
$styles[$prop] = $properties[$prop];
}
}
return $styles;
}
}