Closed HossamElwahsh closed 3 years ago
I create a new class that can handle for windows user
here u can see this, btw I'm using CI3 framework :
`<?php
use NcJoes\OfficeConverter\OfficeConverter;
/* windows user will need this Set Environment for Windows OS
class PDF { public static function convert($pathTarget, $output = false) { /**
*/
try {
// handle windows version
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$converter = new OfficeConverter($pathTarget, null, 'soffice', false);
if ($output != false) {
$converter = new OfficeConverter($pathTarget, $output, 'soffice', false);
}
} else {
// handle linux version
$converter = new OfficeConverter($pathTarget);
if ($output != false) {
$converter = new OfficeConverter($pathTarget, $output);
}
}
$output_pdf = pathinfo($pathTarget, PATHINFO_FILENAME) . '.pdf'; //change the name to pdf
$result = $converter->convertTo($output_pdf);
} catch (Exception $e) {
echo 'Error Caught, ' . $e->getMessage();
return;
}
return $result;
} } `
With Some Tweak in constructor we can make this work on windows. ` public function __construct($filename, $tempPath = null, $bin = 'libreoffice', $prefixExecWithExportHome = true) { if(str_contains(PHP_OS, 'WIN')) { $bin = "soffice"; // soffice: libra office window binary $path = storage_path('app/files'); //@$path for file ouput putenv("HOME=".$path); // adding env variable on server } if ($this->open($filename)) { $this->setup($tempPath, $bin, $prefixExecWithExportHome); } }
`
Thanks for the help guys
Can this work with windows? Do I need any special setup requirements?