Have you searched github? For example https://github.com/PHPOffice/PHPWord
Preview doc, ppt and pdf
Hello, please can you suggest me any package or ways to preview ppt, doc and pdf online using laravel. Thank you soo much in advance for your time.
@jlrdw thank you for your suggestion. I could upload files (pdf, doc, ppt, etc..) in laravel but now i want to open this uploaded file and view it online.
Another post recently discussed same subject. It was the conclusion that something like Google Docs was probably the best bet. Short of that an end user would have to have the software to open such files. No big deal, but hard to get everyone to install it. In other words not everyone will go out of their way to install the free Word viewer.
please follow this link it might help http://stackoverflow.com/questions/27957766/how-do-i-render-a-word-document-doc-docx-in-the-browser-using-javascript
But please not it will open in the iframe you direct dont have any access for same
you can preview it by passing Content-Type headear depend on you file mime type.
e.g. for pdf you can pass header Content-Type: application/pdf
return response()->file(<your file path>, [
'Content-Type' => 'application/pdf'
]);
you can get the file mime type using Storage facade
Storage::mimeType(<your file path>);
All modern browsers have pdf reading capabilities.
@jlrdw @ershakti @bunnypro @gustav1105 thank you for your suggestion and advises.
I learnt that inorder to preview doc, ppt and pdf and other formats i can use google doc viewer for which my application should be in production however i want to implement it in local host.
I could only preview pdf, docs are automatically downloaded:
if($document_name){ $file = base_path().'/public/uploads/'.$document_name; if (file_exists($file)){
$ext =File::extension($file);
if($ext=='pdf'){
$content_types='application/pdf';
}elseif ($ext=='doc') {
$content_types='application/msword';
}elseif ($ext=='docx') {
$content_types='application/vnd.openxmlformats-officedocument.wordprocessingml.document';
}elseif ($ext=='xls') {
$content_types='application/vnd.ms-excel';
}elseif ($ext=='xlsx') {
$content_types='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
}elseif ($ext=='txt') {
$content_types='application/octet-stream';
}
return response(file_get_contents($file),200) ->header('Content-Type',$content_types);
}
else{
exit('Requested file does not exist on our server!');
}
}else{
exit('Invalid Request');
}
}
Unfortunately only pdf can be previewed, other formats are downloaded automatically.
The best possible solution for this problem could be this premium javascript package.
https://www.kukudocs.com/jsDemo
In the demo, you can upload the Docx, Xlsx, Pptx or pdf file then view the document. However, I have used this javascript to view the local document for the intranet web application.
easy try with https://github.com/vish4395/laravel-file-viewer
Please or to participate in this conversation.