PHP處理Word轉(zhuǎn)PDF的方法

2010-10-19 10:18:15來源:作者:

  我們知道,PHP語言的合理運(yùn)用可以幫助我們實(shí)現(xiàn)導(dǎo)出Word文檔的功能。今天我們將為大家介紹PHP處理Word轉(zhuǎn)PDF的相關(guān)實(shí)現(xiàn)方法。

  我們知道,PHP語言的合理運(yùn)用可以幫助我們實(shí)現(xiàn)導(dǎo)出Word文檔的功能。今天我們將為大家介紹PHP處理Word轉(zhuǎn)PDF的相關(guān)實(shí)現(xiàn)方法。

  PHP處理Word轉(zhuǎn)PDF代碼示例:

PHP Code復(fù)制內(nèi)容到剪貼板
  1. <?php   
  2. set_time_limit(0);   
  3. function MakePropertyValue($name,$value,$osm){   
  4. $oStruct = $osm->Bridge_GetStruct   
  5. ("com.sun.star.beans.PropertyValue");   
  6. $oStruct->Name = $name;   
  7. $oStruct->Value = $value;   
  8. return $oStruct;   
  9. }   
  10. function word2pdf($doc_url$output_url){   
  11. $osm = new COM("com.sun.star.ServiceManager")   
  12. or die ("Please be sure that OpenOffice.org  
  13. is installed.\n");   
  14. $args = array(MakePropertyValue("Hidden",true,$osm));   
  15. $oDesktop = $osm->createInstance("com.sun.star  
  16. .frame.Desktop");   
  17. $oWriterDoc = $oDesktop->loadComponentFromURL   
  18. ($doc_url,"_blank", 0, $args);   
  19. $export_args = array(MakePropertyValue   
  20. ("FilterName","writer_pdf_Export",$osm));   
  21. $oWriterDoc->storeToURL($output_url,$export_args);   
  22. $oWriterDoc->close(true);   
  23. }   
  24. $output_dir = "D:/LightTPD/htdocs/";   
  25. $doc_file = "D:/LightTPD/htdocs/2.doc";   
  26. $pdf_file = "2.pdf";   
  27. $output_file = $output_dir . $pdf_file;   
  28. $doc_file = "file:///" . $doc_file;   
  29. $output_file = "file:///" . $output_file;   
  30. word2pdf($doc_file,$output_file);   
  31. ?>  

以上這段代碼就是PHP處理Word轉(zhuǎn)PDF的相關(guān)實(shí)現(xiàn)方法。

關(guān)鍵詞:PHP