Convert DOCX in Laravel using LibreOffice

Supported conversion formats include:

  • pptx => pdf
  • ppt => pdf
  • pdf => pdf
  • docx => pdf, odt, html
  • doc => pdf, odt, html
  • xlsx => pdf
  • xls => pdf
  • png => pdf
  • jpg => pdf
  • jpeg => pdf

Dependencies

First install LibreOffice in your Linux server:

sudo apt-get install libreoffice

Then install the PHP Wrapper for LibreOffice:

composer require ncjoes/office-converter

Usage

My working path is storage so I will use the storage/word_file_1.docx file and convert it to storage/pdf_file_1.pdf

<?php
use NcJoes\OfficeConverter\OfficeConverter;

$doc_path = \Storage::path('word_file_1.docx');
$converter = new OfficeConverter($doc_path);
$converter->convertTo('pdf_file_1.pdf');
?>

Comments (0)

Search Here