diff --git a/Tests/Tag/Html/ButtonTest.php b/Tests/Tag/Html/ButtonTest.php new file mode 100644 index 0000000..2b9edd3 --- /dev/null +++ b/Tests/Tag/Html/ButtonTest.php @@ -0,0 +1,36 @@ +html2pdf = new Html2Pdf(); + $this->button = new Button(); + } + + public function testButtonName() + { + $this->assertEquals('button', $this->button->getName()); + } + + public function testButtonProperties() + { + $properties = [ + 'type' => 'submit', + 'class' => 'btn-primary', + 'background' => '#007bff', + 'color' => '#ffffff' + ]; + + $result = $this->button->open($properties); + $this->assertTrue($result); + } +} diff --git a/Tests/samples/button_test.html b/Tests/samples/button_test.html new file mode 100644 index 0000000..5febd2d --- /dev/null +++ b/Tests/samples/button_test.html @@ -0,0 +1,25 @@ + + + + Button Test + + + + + + + + + + + + + + + diff --git a/Tests/samples/test_buttons.php b/Tests/samples/test_buttons.php new file mode 100644 index 0000000..f7dedf3 --- /dev/null +++ b/Tests/samples/test_buttons.php @@ -0,0 +1,17 @@ +writeHTML($content); + $html2pdf->output('button_test.pdf', 'D'); +} catch (Exception $e) { + echo $e->getMessage(); +} diff --git a/src/Extension/Core/HtmlExtension.php b/src/Extension/Core/HtmlExtension.php index dc9cd2c..0614184 100644 --- a/src/Extension/Core/HtmlExtension.php +++ b/src/Extension/Core/HtmlExtension.php @@ -54,6 +54,7 @@ protected function initTags() new Html\Sup(), new Html\U(), new Html\Strike(), + new Html\Button(), ); } } diff --git a/src/Tag/Html/Button.php b/src/Tag/Html/Button.php new file mode 100644 index 0000000..c3c4cb0 --- /dev/null +++ b/src/Tag/Html/Button.php @@ -0,0 +1,77 @@ +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; + } +}