To register new tags in Html2Pdf, you must wrap them in an extension. An extension must implement the \[Spipu\\Html2Pdf\\Extension\\ExtensionInterface\] interface.
Implementation Requirements
getName(): Returns a unique name for the extension.getTags(): Returns an array of tag objects that the extension provides.
Registering the Extension
Use the addExtension() method on your Html2Pdf instance to activate your new tags:
$html2pdf->addExtension(new \Example\Html2Pdf\Extension\MyExtension());
Core Extensions
The following extensions are included by default:
\Spipu\\Html2Pdf\\Extension\\Core\\HtmlExtension (contains native tags)\Spipu\\Html2Pdf\\Extension\\Core\\SvgExtension
<?php
/**
* Extension Example
*/
namespace Example\Html2Pdf\Extension;
use \Spipu\\Html2Pdf\\Extension\\ExtensionInterface;
/**
* Class MyExtension
*/
class MyExtension implements ExtensionInterface
{
/**
* @var array
*/
private $tagDefinitions = array();
/**
* {@inheritDoc}
*/
public function getName()
{
return 'example_extension';
}
/**
* {@inheritDoc}
*/
public function getTags()
{
if (empty($this->tagDefinitions)) {
$this->tagDefinitions = array(
new \Example\Html2Pdf\Tag\Example(),
new \Example\Html2Pdf\Tag\Other(),
);
}
return $this->tagDefinitions;
}
}