Convert a word document (DOC, DOCX) to PFD using PHP or JavaScript

0

I wonder if there is a possibility of converting a Word file (.doc, .docx) to a .pdf file using Php or JavaScript (or something like that). For example, the user uploads a .docx file that should be saved only in .pdf format - to do the conversion.

    
asked by anonymous 03.06.2018 / 06:38

1 answer

0

phpgearbox / pdf

  

Requires: link

You can use link , you should install via composer:

composer require gears/pdf:*

Then on your composer.json add:

"scripts":
{
    "post-install-cmd": ["PhantomInstaller\Installer::installPhantomJS"],
    "post-update-cmd": ["PhantomInstaller\Installer::installPhantomJS"]
}

Then after uploading select:

<?php
require_once 'vendor/autoload.php';

//Upload vem aqui

\Gears\Pdf::convert('<caminho do documento>/documento.docx', '<caminho aonde será salvo o pdf>/documento.pdf');

PHPOffice / PHPWord

You can use the link that supports several formats:

  • odt
  • RTF
  • Word2007
  • HTML
  • PDF

You should install via composer:

composer require phpoffice/phpword

Example:

<?php
require_once 'vendor/autoload.php';

//Upload vem aqui

$source = '<caminho do documento>/documento.docx';

$phpWord = \PhpOffice\PhpWord\IOFactory::load($source);

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'PDF');
$objWriter->save('<caminho aonde será salvo o pdf>/documento.pdf');
    
03.06.2018 / 08:05