Wallogit.com
2017 © Pedro Peláez
Converts files from one format, such as '.docx' or '.xlsx' to another, such as '.pdf' or '.csv'
Symfony bundle to converts files from one format, such as '.docx' or '.xlsx' to another, such as '.pdf' or '.csv'.
Accepted formats: .docx .doc .xlsx .xls .ppt .pdf .csv .odt .odp .ods and much more, (*1)
$ composer require px-core/libre-office-converter "dev-master"
Composer will install the bundle to your project's vendor/px-core/libre-office-converter directory., (*2)
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new pxCore\LibreOfficeConverterBundle\pxCoreLibreOfficeConverterBundle()
// ...
);
}
$ sudo apt-get install libreoffice
parameters:
# ...
libreoffice: /usr/bin/libreoffice # Default value
On Unix or Linux variants the LibreOffice executable will usually be found in /usr/lib/libreoffice/program/soffice
(link: /usr/bin/libreoffice), (*3)
Exemple1: Convert WORD to PDF:, (*4)
// Create a new instance of pxCore_libreOffice_converter_service
$wordToPdfService = $this->get('pxCore_libreOffice_converter_service');
$webDir = __DIR__ . '/../../../../web';
// The word file path
$wordPath = $webDir . '/word/test.docx';
// The outDir in wich we will put the generated PDF
$outDir = $webDir . '/pdf';
$toFormat = 'pdf';
// Generate the PDF file
$wordToPdfService->convert($wordPath, $outDir, $toFormat);
Exemple2: Convert XLSX to CSV:, (*5)
// Create a new instance of pxCore_libreOffice_converter_service
$pxCoreLibreOfficeConverter = $this->get('pxCore_libreOffice_converter_service');
$webDir = __DIR__ . '/../../../../web';
// The xlsx file path
$xlsxPath = $webDir . '/xlsx/test2.xlsx';
// The outDir in wich we will put the generated csv file
$outdir = $webDir . '/csv';
$toFormat = 'csv';
// Generate the csv file
$pxCoreLibreOfficeConverter->convert($xlsxPath, $outdir, $toFormat);
Enjoy!, (*6)