Convert HTML To PDF
first of all you need to install package phpword
composer require phpoffice/phpword
Now:
<?php
require "vendor/autoload.php";
$pw = new \PhpOffice\PhpWord\PhpWord();
$section = $pw->addSection();
$html = "<h1>HELLO WORLD!</h1>";
$html .= "<p>This is a paragraph of random text</p>";
$html .= "<table><tr><td>A table</td><td>Cell</td></tr></table>";
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;filename="convert.docx"');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($pw, 'Word2007');
$objWriter->save('php://output');
?>
Great Post! Very well explained HTML - RTF Converter
ReplyDelete