I used laravel for my application, and dompdf is located in:
../seller/DOMPDF/DOMPDF
What I wanted to achieve was to convert my .docx file (Microsoft Word) to a .pdf file. The docx file was generated by phpWord by loading the template file and replacing the values.
Here's a snippet:
// Get the absolute path of the template file $wordTemplatePath = $this->getDocumentTemplatePath('resignation.docx'); // Load the template file $document = $this->phpWord->loadTemplate($wordTemplatePath); // This will be filled with data $wordData = [] .... Process to fill the data ..... // Replace value to actual word document $this->setTemplateValues($wordData, $document); // Generate its filename $file = $this->generateFileName('Retirement-Certificate.docx', $id); // Fetch the absolute path to save the document $filepath = $this->getSavePath($file); // Save the word document $document->saveAs( $filepath );
After that a .docx file will be created. I also wanted to make a PDF version. so I found and found this piece of code and added to my code:
\PhpOffice\PhpWord\Settings::setPdfRendererPath('../vendor/dompdf/dompdf'); \PhpOffice\PhpWord\Settings::setPdfRendererName('DOMPDF'); //Load temp file $phpWord = \PhpOffice\PhpWord\IOFactory::load($filepath); //Save it $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'PDF'); $xmlWriter->save('result.pdf');
But I got this error:
{"error": {"type":"PhpOffice\\PhpWord\\Exception\\Exception","message":"PDF rendering library or library path has not been defined.", "file":"C:\\xampp\\htdocs\\vagrant\\vendor\\phpoffice\\phpword\\src\\PhpWord\\Writer\\PDF.php", "line":49}}
How do I make DomPDF as the author of PDF for PHPWord? I can not find any other options, so I ask here. I hope you can help me. Thanks!
source share