/** * 获取文档详细信息 */ public function fileDetails() { $name = I('get.name'); $res = M('resources'); $result = $res->where("name = '{$name}'")->find(); if (!$result) { $data = array('code' => -1, 'msg' => '操作失败'); $this->ajaxReturn($data); return; } else { // 将文档转换为pdf格式 set_time_limit(0); $str = str_replace('\\', '/', dirname(__FILE__)); $file_sub_path = substr($str, 0, strpos($str, '/Application')); $filename = substr($result['src'], strpos($result['src'], '/Public')); $path = $file_sub_path . $filename; $output_file_path = substr($path, 0, strrpos($path, '.')); $output_file = $output_file_path . '.pdf'; //输出的pdf 文件地址 $swf_file = $output_file_path . '.swf'; // 判断是否已将文档转换为swf格式 if (is_dir($swf_file)) { $src_swf = substr($swf_file, strpos($swf_file, '/server')); $data = array('code' => 1, 'msg' => '操作成功', 'src_pdf' => $src_swf, 'data' => $result); $this->ajaxReturn($data); return; } $path = "file:///" . $path; $output_file1 = "file:///" . $output_file; import("Org.Util.OfficeToPdf"); word2pdf($path, $output_file1); $file = "../SWFTools"; $swftools_path = realpath($file); $pdf2swf = $swftools_path . "/pdf2swf.exe"; $swfcombine = $swftools_path . "/swfcombine.exe"; $rfxview = $swftools_path . "/rfxview.swf"; $cmd1 = $pdf2swf . " " . $output_file . " -o " . $swf_file; $cmd2 = $swfcombine . " -X 595 -Y 841 " . $rfxview . " viewport=" . $swf_file . " -o " . $swf_file; exec($cmd1); exec($cmd2); $src_swf = substr($swf_file, strpos($swf_file, '/server')); $data = array('code' => 1, 'msg' => '操作成功', 'src_pdf' => $src_swf, 'data' => $result); } $this->ajaxReturn($data); return; }
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); } $doc_file = "Jazz.doc"; $pdf_file = "Jazz.pdf"; $output_dir = ""; $output_file = $output_dir . $pdf_file; # $doc_file = "file:///" . $doc_file; # $output_file = "file:///" . $output_file; word2pdf($doc_file, $output_file);