RubyPDF Blog English,Open Source,PDF,tutorial Word to PDF Converter in PHP using OpenOffice (Word2PDF)

Word to PDF Converter in PHP using OpenOffice (Word2PDF)

Lots of people want to convert Word docs into PDF’s (Word2PDF). Here’s a Windows PHP converter of Word documents to PDF using OpenOffice via a COM wrapper of the OpenOffice API’s. It’s a lot of description for something fairly simple.

$oStruct->Name = $name;
$oStruct->Value = $value;
return $oStruct;
function word2pdf($doc_url, $output_url){
//Invoke the service manager
$osm = new COM("") or die ("Please be sure that 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("");
//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));
//Write out the PDF
$output_dir = "C:/dev/openofficeintegration/docconverter/";
$doc_file = "C:/dev/openofficeintegration/docconverter/DpmR5Reqv1.20.doc";
$pdf_file = "DpmR5Reqv1.20.pdf";
$output_file = $output_dir . $pdf_file;
$doc_file = "file:///" . $doc_file;
$output_file = "file:///" . $output_file;


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.