Wednesday, September 24, 2008

Php Class : Word to PDF Converter in PHP using OpenOffice (Word2PDF)

Php Class : Word to PDF Converter in PHP using OpenOffice (Word2PDF)

Lots of people want to convert Word docs into PDF's (Word2PDF). Currenty there is no php class available to directly conver the doc to pdf file.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.
But to work around we need to install the openoffice in our windows system

<?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));
//Write out the PDF
$oWriterDoc->storeToURL($output_url,$export_args);
$oWriterDoc->close(true);
}
$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;
word2pdf($doc_file,$output_file);
?>

================

More info :
http://www.wynia.org/wordpress/word-to-pdf-converter-in-php-word2pdf/

1 comment:

Unknown said...

Thank you for such a great info. I was able to come across this online service that allows you to easily edit your PDF documents. (http://goo.gl/kfjBoV) You can fill out PDF form, save it, fax it, and email it. You might want to try, it was good!

Post a Comment