Hi All,
As part of a document creation process, I currently create PDF documents from word documents using PHP COM with MS Word (to create a Postscript Doc), then ghostscript to do the Postscript to PDF. It works OK but the quality of the final PDF is not quite up to scratch for commercial documents...(I'm happy supply the implementation if anyone wants it).
I've found an alternative using PHP COM with OpenOffice (thanks to: http://www.wynia.org/wordpress/?page_id=94). I have implemented the code below, but get an error:
“Unable to obtain IDispatch interface for CLSID {82154420-0FBF-11D4-8313-005004526AB4}: ”
I have installed OpenOffice...(I've tested with versions 1.1 and 2.0).
Searching around the web, I can only find others with the same problem, but no solution. I really would like to get this to work as it looks like a great solution.
Thanks...
<?php
set_time_limit(600);
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));
//Write out the PDF
$oWriterDoc->storeToURL($output_url,$export_args);
$oWriterDoc->close(true);
}
$output_dir = "C:/";
$doc_file = "C:/Invoice.doc";
$pdf_file = "Invoice.pdf";
$output_file = $output_dir . $pdf_file;
$doc_file = "file:///" . $doc_file;
$output_file = "file:///" . $output_file;
word2pdf($doc_file,$output_file);
?>