En utilisant le logiciel OpenOffice, il est possible de
convertir des fichiers générés sous Microsoft Word ou Excel en PDF.
Voici comment procéder ...
Au préalable, vous devez installer OpenOffice sur l'ordinateur ou le serveur sur lequel votre site Internet tourne.
Les fonctions génériques à implémenter :
private function MakePropertyValue($name,$value,$osm)
{
$oStruct = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$oStruct->Name = $name;
$oStruct->Value = $value;
return $oStruct;
}
private function word2pdf($doc_url, $output_url)
{
$osm = new \COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");
$args = array($this->MakePropertyValue("Hidden",true,$osm));
$oDesktop = $osm->createInstance("com.sun.star.frame.Desktop");
if(file_exists($doc_url))
{
$oWriterDoc = $oDesktop->loadComponentFromURL("file:///".$_SERVER['DOCUMENT_ROOT'].'/'.$doc_url,"_blank", 0, $args);
$export_args = array($this->MakePropertyValue("FilterName","writer_pdf_Export",$osm));
$oWriterDoc->storeToURL($output_url,$export_args);
$oWriterDoc->close(true);
}
}
Appel de la fonction « word2pdf » :
$this->word2pdf('attachments/'.$currentEntity->getNameAttachment(),"file:///".$_SERVER['DOCUMENT_ROOT']."/attachments/".$nameFile.".pdf");