I want to preview created new Word file in a browser using PHPWord in Laravel
I have successfully managed to make a word file but now I want to preview it instead of downloading.
I have a system in it I am proving a file when it created. PDF and Image files are working fine. But the Word file is not getting preview in the browser.
Here is the function
public function saveAndPreviewDocx()
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$description_data = "This is a sample text and i want it to preview this in a browser in word file";
$section->addText($description_data);
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
try {
$objWriter->save(storage_path('new_doc12.docx'));
} catch (Exception $e) {
}
// How can i view the file in the browser form here or form the view using the phpWord
}
This function is creating a file but I want to preview the created file in the browser.
in a way of finding a solution, I found that I can view word files using google Docs view or Microsoft office view but they are not useful to me because I have a private server.
I Have tried the Google Docs Viewer & Microsoft Office Viewer but in my private server it's not working.
So I want any clean solution to solve this word preview in the web browser as we see other files like PDF and all.