You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TemplateProcessor not working with IOFactory::createWriter().
PhpOffice\PhpWord\IOFactory::createWriter(): Argument 1 ($phpWord) must be of type PhpOffice\PhpWord\PhpWord, PhpOffice\PhpWord\TemplateProcessor
Steps to Reproduce
Please provide a code sample that reproduces the issue.
<?php$templateProcessor = newTemplateProcessor('temp.docx');
$FullFileName = 'NewTemp.pdf' ;
// Save the document to a temporary file$filename = tempnam(sys_get_temp_dir(), 'NewTemp' ) . '.docx';
$templateProcessor->saveAs($filename);
// Convert Word document to HTML$htmlWriter = IOFactory::createWriter($templateProcessor, 'HTML');
$htmlContent = $htmlWriter->saveToString();
// Initialize DomPDF$options = newOptions();
$options->set('isHtml5ParserEnabled', true);
$options->set('isPhpEnabled', true);
$dompdf = newDompdf($options);
// Load HTML content into DomPDF$dompdf->loadHtml($htmlContent);
// Set paper size (optional)$dompdf->setPaper('A4', 'portrait');
// Render PDF (output)$dompdf->render();
// Set headers for a PDF downloadheader('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename='.$FullFileName);
// Output the PDF content to the browserecho$dompdf->output();
// Delete the temporary Word documentunlink($wordFilePath);
Context
Please fill in your environment information:
PHP Version: "^8.1"
PHPWord Version: "^1.2.0"
Mpdf Version : "^8.2"
Tecnickcom/tcpdf : "^6.2.13"
The text was updated successfully, but these errors were encountered:
I don't think the template processor was designed to work with anything other than Word2007 format. However, since you've saved the output file, you should be able to read it back in:
// Convert Word document to HTML$reader = new \PhpOffice\PhpWord\Reader\Word2007();
$phpWord = $reader->load($filename);
$htmlWriter = new \PhpOffice\PhpWord\Writer\HTML($phpWord)
$htmlContent = $htmlWriter->saveToString();
Describe the Bug
TemplateProcessor not working with IOFactory::createWriter().
PhpOffice\PhpWord\IOFactory::createWriter(): Argument 1 ($phpWord) must be of type PhpOffice\PhpWord\PhpWord, PhpOffice\PhpWord\TemplateProcessor
Steps to Reproduce
Please provide a code sample that reproduces the issue.
Context
Please fill in your environment information:
The text was updated successfully, but these errors were encountered: