On the response of @henriquedpereira, Phpdocx has two versions a with LGPL license and Pro, the first is free (attention LGPL license) and the last yes is paid. Phpdocx free allows you to dynamically generate docx files with simple formatting options such as lists, page numbering and tables, watermarks are not inserted in the test period or limit the amount of documents you can generate. If the watermark is not a nuisance already meets your need.
However there is a great library to access Office files, is the Phpoffice/Phpword
To install add to require:
of your composer.json
(it is necessary to have the dompdf
also to write the PDF):
{
"require": {
"dompdf/dompdf": "0.6.*",
"phpoffice/phpword": "v0.13.*"
}
}
And then run on the terminal or cmd:
cd c:\wamp\www\projeto
composer update
To convert a Word to PDF you only need to import the libraries (you will need to use composer
), follows an example (source: https://github.com/PHPOffice/PHPWord):
<?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);
Unfortunately in the version 1.3.0 was definitely removed the custom autoloader, which allowed installing without composer
the library, I know it seems a difficult situation, I understand that the composer
seems complicated, but in fact it is easier to structure a project than manually, besides that if you need to update something, add or remove the composer
does it for you.
but the PHPDOCX library is paid for. I was interested in a free
– pc_oc
@pc_oc is not paid, has two versions a with LGPL and Pro license, this last yes is paid, as Henrique said (that has the paid and free version).
– Guilherme Nascimento
@Guillhermenascimento but the free version must be limited
– pc_oc
@pc_oc then only the
phpoffice/phpword
:)– Guilherme Nascimento
@Guilhermenascimento I at the time ended up doing everything in html and converting to PDF since it was the only solution I found at the time. It was about 40 pages I had to..
– pc_oc