Is there a library that can view documents (doc, docx) to be viewed in the browser on an intranet without the need for external resources like google docs or office live? I need some component that does not need external access.
Is there a library that can view documents (doc, docx) to be viewed in the browser on an intranet without the need for external resources like google docs or office live? I need some component that does not need external access.
Practice solution, if it is to render only, convert to PDF, this technically solves a lot of compatibility problem between different browsers and even absence of plugins or activex (Internet Explorer) popular has already natively embedded PDF readers:
Mobile browsers apparently already have internal built-in APIs for PDF rendering
Workarounds (removed from SOen ):
Office 365:
<iframe src="https://view.officeapps.live.com/op/embed.aspx?src={URLDODOCUMENTO}"></iframe>
Use google docs:
<iframe src="http://docs.google.com/gview?url={URLDODOCUMENTO}&embedded=true"></iframe>
Note: change
{URL DO DOCUMENTO}
to the desired URL
Although I really believe that it is best to already send in PDF format to the production server for the following reasons:
Still, you may want to do the conversion on the server, if the server is a linux, install the unoconv , some linux will have this via repository, with a SSH
and apt-get
or yum
you might be able to install, distros supported:
Or you can compile on the server:
Requirements: unoconv requires Python and requires LibreOffice or OpenOffice with UNO .
An example of using the terminal:
$ /home/compilado/unoconv /home/user/meudocumento.doc
In PHP you can use:
<?php
//Seta o arquivo que será convertido (pode ser um arquivo vindo de um upload)
$input = '/home/user/meudocumento.doc';
//Define aonde será salvo
$output = '/home/user/meudocumento.pdf';
//Caminho do executável acaso não esteja global, se estiver global basta setar 'unoconv'
$exec = '/home/compilado/unoconv';
//Escapar os argumentos (este é necessário para evitar problemas com espaços e acentos)
$inputarg = escapeshellarg($input);
$outputarg = escapeshellarg($output);
//Executa o comando
$resultado = shell_exec($exec . ' -f pdf -o ' . $outputarg . ' ' . $inputarg);
//Resposta da conversão
var_dump($resultado);
As I explained in this response link , PHPOffice offers such support
To install add to require:
of your composer.json
(you must have dompdf
also to write the PDF):
{
"require": {
"dompdf/dompdf": "0.6.*",
"phpoffice/phpword": "v0.13.*"
}
}
And then run in terminal or cmd:
cd c:\wamp\www\projeto
composer update
To convert a Word to PDF you only need to import to libraries (you will need to use composer
), follow an example (source: link ):
<?php
require_once 'bootstrap.php';
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\IOFactory;
Settings::setPdfRendererPath('vendor/dompdf/dompdf');
Settings::setPdfRendererName('DomPDF');
$temp = IOFactory::load('pasta/doc.docx');
$xmlWriter = IOFactory::createWriter($temp , 'PDF');
$xmlWriter->save('pasta/doc.pdf', true);
If you are using PHP7, there is a BUG link , however in the dev from the repository the problem has already been fixed:
{ "require": { "phpoffice/phpword": "dev-develop" } }
Using repositories / branchs in development can be a risk, I recommend that you test well before.