Read Word and Generate a PDF with PHP

1

I'm using the library PHPWord to open a Word template has some data that is generated dynamically and result in a Word that the user downloads, my question would be, instead of sending a Word send a PDF of the template generated? And if you can, how would it be?

This is the code I use to launch the Word download.

Thank you.

 $filedescargar = "Contrato.docx";
 header('Content-Description: File Transfer');
 header('Content-Type: application/octet-stream; charset=utf-8');
 header("Content-Disposition: attachment; filename=".$filedescargar."; charset=utf-8");
 header('Content-Transfer-Encoding: binary');
 header('Expires: 0');
 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 header('Pragma: public');
 header('Content-Length: '.filesize($filedescargar));

 readfile($filename);
    
asked by M. Gress 20.04.2017 в 15:58
source

1 answer

1

For a similar case, what I did was generate the Word file and then convert it to PDF, I share what I did to be able to do the conversion:

  • Install libreoffice libraries (this is for a mac but you can download it for any OS):
  • link

  • Install the unoconv tool (this I ran on a mac but you can install it on any OS):

    brew install unoconv --HEAD

  • Install and use the PHP-unoconv library to do the conversion:

  • link

        
    answered by 20.04.2017 в 20:02