org_heigl / html-to-pdflib
Convert HTML for usage in PDFlib
Requires
- php: ^7.4 || ^8.0
- ext-dom: *
Requires (Dev)
- phpunit/phpunit: ^9.3
Suggests
- roave/better-reflection: For using ConverterList::createViaBetterReflection
This package is auto-updated.
Last update: 2024-10-19 19:57:01 UTC
README
An extendable library to convert HTML-Content to text usable with textflows of PDFlib
Installation
Install the package via composer like this:
composer require org_heigl/html-to-pdflib
Usage
In your PHP-Code you can use the package like this:
$converter = new Converter(); $pdflibtext = $converter->convert($htmlcontent); // $pdflibtext now contains calls to macros. // The macros themselves need to be prepend to the text though!! $pdflibtext = '<macro { bold {fontname=Helvetica fontsize=12 encoding=winansi} bolditalic {fontname=Helvetica fontsize=8 encoding=winansi} italic {fontname=Helvetica fontsize=8 encoding=winansi} }>' . $pdflibtext;
Alternatively – to get full flexibility – you can create the Converter with your own ConverterList like this:
use Org_Heigl\HtmlToPdflib\Converter; use Org_Heigl\HtmlToPdflib\ConverterList; use Org_Heigl\HtmlToPdflib\Converter\Em; use Org_Heigl\HtmlToPdflib\Converter\Li; use Org_Heigl\HtmlToPdflib\Converter\Ol; use Org_Heigl\HtmlToPdflib\Converter\P; use Org_Heigl\HtmlToPdflib\Converter\Strong; use Org_Heigl\HtmlToPdflib\Converter\Ul; use Org_Heigl\HtmlToPdflib\Factory; $converter = new Converter(Factory::fromConverterList(ConverterList::createViaReflection([ 'em' => Em::class, 'li' => Li::class, 'ol' => Ol::class, 'p' => P::class, 'strong' => Strong::class, 'ul' => Ul::class, ])));
This allows you to also add your own Converter-implementations as long as they implement the ConvertertInterface.
Currently the following macros are defined:
- bold
- bolditalic
- italic
The following HTML-Tags are currently supported:
- em
- li
- ol
- p
- strong
- ul
Further Tags can be added. Feel free to fork this repository and open a PullRequest for further tags.
Contributing
Contributions are welcome!
License
This package is licensed unter the MIT-License.