dompdfphpword

DomPDF Class PreserveText not found


I downloaded and installed the dompdf release http://dompdf_3-0-2.zip/

I am not using composer, so I added this line:

require_once '../dompdf/autoload.inc.php';

Running some sample code:

$phpWord = IOFactory::load('myfile.docx');
$htmlWriter=IOFactory::createWriter($phpWord,'HTML');
ob_start();
$htmlWriter->save('php://output');
$html = ob_get_clean();
$options = new Options();
$options->set('isHtml5ParserEnabled',true);
$dompdf = new Dompdf($options);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4','portrait');
$dompdf->render();
file_put_contents('myfile.pdf',$dompdf->output());

I get this error:

Class PhpOffice\PhpWord\Writer\HTML\Element\PreserveText not found in /php-word/PHPWord/src/PhpWord/Writer/HTML/Element/PreserveText.php


Solution

  • To save time for anyone who encounters this same error, it was cause because the docx file had graphics and a table of contents. Remove the graphics and remove the table of contents and the error should disappear.