Text Document Generation Demo

PhpWord https://github.com/PHPOffice/PHPWord

This is a proof of concept for generating text documents (Open Document (odt), Word (docx) and Portable Document Format (pdf)) files from HTML and table data using the PhpWord library. Edit the HTML and table data below and press one of the document type button at the bottom to create a document.


Adding element via HTML

Some well formed HTML snippet needs to be used

With for example some1 inline formatting1

Without paragraph tag some1 inline formatting1

Unordered (bulleted) list:

  • Item 1
  • Item 2
    • Item 2.1
    • Item 2.1

Ordered (numbered) list:

  1. Item 1
  2. Item 2

Table data Click cells to edit


require_once 'vendor/phpoffice/phpword/src/PhpWord/Autoloader.php';
$phpWord = new PhpWord\PhpWord();
$section $phpWord->addSection();
            if (
$data) {
$phpWord->addTableStyle('tableStyle', array(
'borderSize' => 1,
'borderColor' => 'EEEEEE',
$table $phpWord->addSection()->addTable('tableStyle');
                if (!empty(
$columns)) {
$row $table->addRow(null, array());
                    foreach (
$columns as $name) {
$row->addCell(2500, array(
'bgColor' => 'DDDDDD'
'valign' => 'center'))
addText(htmlspecialchars($name), array(
'bold' => true
'align' => 'center'));
                foreach (
$data as $set) {
$row $table->addRow();
                    foreach (
$set as $item) {
            switch (
$extension) {
$writer PhpWord\IOFactory::createWriter($phpWord'PDF');
$writer PhpWord\IOFactory::createWriter($phpWord'Word2007');
$writer PhpWord\IOFactory::createWriter($phpWord'ODText');