Regarding the answer from @henriquedpereira , PHPdocX has two versions a licensed LGPL and Pro, the The first one is free (LGPL license attention) and the last one is paid. PHPdocX free allows you to dynamically generate docx files with simple formatting options such as lists, page and table numbering, watermarks are not inserted in the test period or limit on the amount of documents you can generate. If the watermark is not an inconvenience it already meets your need.
However, there is a great library for accessing Office files, the PHPOffice / PHPWord
To install add to require:
of your composer.json
( dompdf
is also required 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);
Unfortunately in 1.3.0 I have finally removed the custom autoloader, which allowed me to install without composer
the library, I know it seems a difficult situation, I understand that composer
seems complicated, but in fact it is easier to structure a project than manually, outside if you need to update something, add or remove composer
do it for you.