PHP processing Word to PDF is still a difficult problem for beginners. This article describes how to implement this function.
- 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 ){
- $ Osm = new COM ("com. sun. star. ServiceManager") or die ("Please be sure that OpenOffice.org is installed. n ");
- $ Args = array (MakePropertyValue ("Hidden", true, $ osm ));
- $ ODesktop = $ osm-> createInstance ("com. sun. star. frame. Desktop ");
- $ OWriterDoc = $ oDesktop-> loadComponentFromURL ($ doc_url, "_ blank", 0, $ args );
- $ Export_args = array (MakePropertyValue ("FilterName", "writer_pdf_Export", $ osm ));
- $ OWriterDoc-> storeToURL ($ output_url, $ export_args );
- $ OWriterDoc-> close (true );
- }
-
- $ Output_dir = "D:/LightTPD/htdocs /";
- $ Doc_file = "D:/LightTPD/htdocs/2.doc ";
- $ Pai_file = "2.pdf ";
- $ Output_file = $ output_dir. $ pai_file;
- $ Doc_file = "file: //". $ doc_file;
- $ Output_file = "file: //". $ output_file;
- Word2pdf ($ doc_file, $ output_file );
- ?>