Conversion de word en pdf en php5
Résolu
Bonjour,
Je veux convertir un fichier word en pdf en php 5 j'ai trouvé ce code sur le net:
<?php
set_time_limit(0);
function MakePropertyValue($name,$value,$osm){
$oStruct = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$oStruct->Name = $name;
$oStruct->Value = $value;
return $oStruct;
}
function word2pdf($doc_url, $output_url){
//Invoke the OpenOffice.org service manager
$osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");
//Set the application to remain hidden to avoid flashing the document onscreen
$args = array(MakePropertyValue("Hidden",true,$osm));
//Launch the desktop
$oDesktop = $osm->createInstance("com.sun.star.frame.Desktop");
//Load the .doc file, and pass in the "Hidden" property from above
$oWriterDoc = $oDesktop->loadComponentFromURL($doc_url,"_blank", 0, $args);
//Set up the arguments for the PDF output
$export_args = array(MakePropertyValue("FilterName","writer_pdf_Export",$osm));
//print_r($export_args);
//Write out the PDF
$oWriterDoc->storeToURL($output_url,$export_args);
$oWriterDoc->close(true);
}
$output_dir = ".";
$doc_file = "./monfichier.docx";
$pdf_file = "test.pdf";
$output_file = $output_dir . $pdf_file;
$doc_file = "file:///" . $doc_file;
$output_file = "file:///" . $output_file;
word2pdf($doc_file,$output_file);
?>
mais ça marche pas!
voiçi les erreurs
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object 'com.sun.star.ServiceManager' in C:\wamp\www\Site\fichier.php on line 12
( ! ) com_exception: Failed to create COM object 'com.sun.star.ServiceManager': Syntaxe incorrecte in C:\wamp\www\Site\fichier.php on line 12
Quelqu'un a une idée ? j'ai besoins de vos aides.
Merci d'avance
Je veux convertir un fichier word en pdf en php 5 j'ai trouvé ce code sur le net:
<?php
set_time_limit(0);
function MakePropertyValue($name,$value,$osm){
$oStruct = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$oStruct->Name = $name;
$oStruct->Value = $value;
return $oStruct;
}
function word2pdf($doc_url, $output_url){
//Invoke the OpenOffice.org service manager
$osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");
//Set the application to remain hidden to avoid flashing the document onscreen
$args = array(MakePropertyValue("Hidden",true,$osm));
//Launch the desktop
$oDesktop = $osm->createInstance("com.sun.star.frame.Desktop");
//Load the .doc file, and pass in the "Hidden" property from above
$oWriterDoc = $oDesktop->loadComponentFromURL($doc_url,"_blank", 0, $args);
//Set up the arguments for the PDF output
$export_args = array(MakePropertyValue("FilterName","writer_pdf_Export",$osm));
//print_r($export_args);
//Write out the PDF
$oWriterDoc->storeToURL($output_url,$export_args);
$oWriterDoc->close(true);
}
$output_dir = ".";
$doc_file = "./monfichier.docx";
$pdf_file = "test.pdf";
$output_file = $output_dir . $pdf_file;
$doc_file = "file:///" . $doc_file;
$output_file = "file:///" . $output_file;
word2pdf($doc_file,$output_file);
?>
mais ça marche pas!
voiçi les erreurs
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object 'com.sun.star.ServiceManager' in C:\wamp\www\Site\fichier.php on line 12
( ! ) com_exception: Failed to create COM object 'com.sun.star.ServiceManager': Syntaxe incorrecte in C:\wamp\www\Site\fichier.php on line 12
Quelqu'un a une idée ? j'ai besoins de vos aides.
Merci d'avance
2 réponses
-
non, je travail avec wampserver. c.à.d ce code marche qu'avec apatch open Office ?
-
-
-
j'ai installer openOffice mais je n'est pas compris comment utiliser la librairie d'openOffice
-
de toute façon vous aurez des problèmes avec ce genre de librairie.
J'imagine q"un jour ce site sera mise en ligne sur internet, et là vous aurez un gros problème car vous ne pourrez pas installer OpenOffice chez votre hébergeur.
Utilisez plutôt des librairies purement PHP.
voir ici par exemple (il y a une version gratuite) https://www.phpdocx.com/
faire recherche sur Google (php word to pdf) et vous verrez qu'il y en a d'autres -
-