當前位置:首頁 » 編程語言 » openofficephp

openofficephp

發布時間: 2022-04-16 13:57:58

1. php用openoffice轉換文檔到pdf為什麼有些文件報錯non-subject

可能是原文件的數據編程碼被損壞。如果在不懂,推薦你去後盾人視頻平台,那裡學習視頻非常多。

2. PHP 調用openoffice組件,如果openoffice是4.X版本的,在new COM的時候會報錯,3.4.1版本是正常的

PHP 調用openoffice組件,如果openoffice是4.X版本的,在new COM的時候會報錯,3.4.1版本是正常的

3. 最近想用PHP轉換DOC文檔,我用OpenOffice 4創建一個com對象提示代碼超時,究竟是什麼問題

OpenOffice
沒有注冊com組件不能直接調用

4. 如何利用openoffice讀取word文檔,並輸出在頁面上(HTML)

將Word轉Html的原理是這樣的:
1、客戶上傳Word文檔到伺服器
2、伺服器調用OpenOffice程序打開上傳的Word文檔
3、OpenOffice將Word文檔另存為Html格式
4、Over
至此可見,這要求伺服器端安裝OpenOffice軟體,其實也可以是MS Office,不過OpenOffice的優勢是跨平台,你懂的。恩,說明一下,本文的測試基於 MS Win7 Ultimate X64 系統。
下面就是規規矩矩的實現。
1、下載OpenOffice,
2、下載Jodconverter 這是一個開啟OpenOffice進行格式轉化的第三方jar包。
3、泡杯熱茶,等待下載。

4、安裝OpenOffice,安裝結束後,調用cmd,啟動OpenOffice的一項服務:C:\Program Files (x86)\OpenOffice.org 3\program>soffice -headless -accept="socket,port=8100;urp;"

5、打開eclipse
6、喝杯熱茶,等待eclipse打開。
7、新建eclipse項目,導入Jodconverter/lib 下得jar包。

* commons-io
* jodconverter
* juh
* jurt
* ridl
* slf4j-api
* slf4j-jdk14
* unoil
* xstream

8、Coding...

查看代碼

package com.mzule.doc2html.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ConnectException;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;

/**
* 將Word文檔轉換成html字元串的工具類
*
* @author MZULE
*
*/
public class Doc2Html {

public static void main(String[] args) {
System.out
.println(toHtmlString(new File("C:/test/test.doc"), "C:/test"));
}

/**
* 將word文檔轉換成html文檔
*
* @param docFile
* 需要轉換的word文檔
* @param filepath
* 轉換之後html的存放路徑
* @return 轉換之後的html文件
*/
public static File convert(File docFile, String filepath) {
// 創建保存html的文件
File htmlFile = new File(filepath + "/" + new Date().getTime()
+ ".html");
// 創建Openoffice連接
OpenOfficeConnection con = new SocketOpenOfficeConnection(8100);
try {
// 連接
con.connect();
} catch (ConnectException e) {
System.out.println("獲取OpenOffice連接失敗...");
e.printStackTrace();
}
// 創建轉換器
DocumentConverter converter = new OpenOfficeDocumentConverter(con);
// 轉換文檔問html
converter.convert(docFile, htmlFile);
// 關閉openoffice連接
con.disconnect();
return htmlFile;
}

/**
* 將word轉換成html文件,並且獲取html文件代碼。
*
* @param docFile
* 需要轉換的文檔
* @param filepath
* 文檔中圖片的保存位置
* @return 轉換成功的html代碼
*/
public static String toHtmlString(File docFile, String filepath) {
// 轉換word文檔
File htmlFile = convert(docFile, filepath);
// 獲取html文件流
StringBuffer htmlSb = new StringBuffer();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(htmlFile)));
while (br.ready()) {
htmlSb.append(br.readLine());
}
br.close();
// 刪除臨時文件
htmlFile.delete();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// HTML文件字元串
String htmlStr = htmlSb.toString();
// 返回經過清潔的html文本
return clearFormat(htmlStr, filepath);
}

/**
* 清除一些不需要的html標記
*
* @param htmlStr
* 帶有復雜html標記的html語句
* @return 去除了不需要html標記的語句
*/
protected static String clearFormat(String htmlStr, String docImgPath) {
// 獲取body內容的正則
String bodyReg = "<BODY .*</BODY>";
Pattern bodyPattern = Pattern.compile(bodyReg);
Matcher bodyMatcher = bodyPattern.matcher(htmlStr);
if (bodyMatcher.find()) {
// 獲取BODY內容,並轉化BODY標簽為DIV
htmlStr = bodyMatcher.group().replaceFirst("<BODY", "<DIV")
.replaceAll("</BODY>", "</DIV>");
}
// 調整圖片地址
htmlStr = htmlStr.replaceAll("<IMG SRC=\"", "<IMG SRC=\"" + docImgPath
+ "/");
// 把<P></P>轉換成</div></div>保留樣式
// content = content.replaceAll("(<P)([^>]*>.*?)(<\\/P>)",
// "<div$2</div>");
// 把<P></P>轉換成</div></div>並刪除樣式
htmlStr = htmlStr.replaceAll("(<P)([^>]*)(>.*?)(<\\/P>)", "<p$3</p>");
// 刪除不需要的標簽
htmlStr = htmlStr
.replaceAll(
"<[/]?(font|FONT|span|SPAN|xml|XML|del|DEL|ins|INS|meta|META|[ovwxpOVWXP]:\\w+)[^>]*?>",
"");
// 刪除不需要的屬性
htmlStr = htmlStr
.replaceAll(
"<([^>]*)(?:lang|LANG|class|CLASS|style|STYLE|size|SIZE|face|FACE|[ovwxpOVWXP]:\\w+)=(?:'[^']*'|\"\"[^\"\"]*\"\"|[^>]+)([^>]*)>",
"<$1$2>");
return htmlStr;
}

}

5. php怎麼使用openoffice實現office文件轉pdf文件

你需要幾下載幾個包,然後安裝配置一下:
OOo_3.3.0_Linux_x86_install-rpm-wJRE_en-US.tar.gz
OOo-SDK_3.3.0_Linux_x86_install-rpm_en-US.tar.gz
jodconverter.2.2.2

1. 安裝openoffice3
tar zxvf OOo_3.3.0_Linux_x86_install-rpm-wJRE_en-US.tar.gz
cd OOO330_m20_native_packed-1_en-US.9567/RPMS
rpm -ivh *.rpm --nodeps --force
安裝後的默認目錄是在:/opt/目錄下面
啟動服務:
/opt/openoffice.org3/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &

開機啟動:
vi /etc/rc.local
在最後面加入啟動語句

2. 安裝OpenOffice SDK3.3

tar zxvf OOo-SDK_3.3.0_Linux_x86_install-rpm_en-US.tar.gz
cd OOO330_m20_native_packed-1_en-US.9567/RPMS/
rpm -vih *.rpm
3. 安裝jodconverter.2.2.2 ,安裝了這個之後就已經可以實現DOC轉PDF了。
這個安裝很簡單,直接上網站下一個這個東東回來。
解壓,復制到一個目錄裡面去,就能直接用了,調用它裡面的/lib/jodconverter-cli-2.2.2.jar這個玩意兒就行,可以直接運行命令測試:

java -jar /usr/local/wenku/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar /tmp/1.doc /tmp/1.pdf

6. PHP實現word以及其他常見格式文檔在線預覽

不用插件你就開玩笑了,這個不是簡單的程序問題,還要破解文件格式,插件就只需要一個東西,
openoffice
,非常好用

7. 求問php 利用openoffice把office轉成pdf格式,該怎麼處理

如題 從網上找到代碼PHP code 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($this->MakePropertyValue("Hidden",true,$osm)); //Launch the desktop $top = $osm->createInstance("com.sun.star.frame.Desktop"); //Load the .doc file, and pass in the "Hidden" property from above $oWriterDoc = $top->loadComponentFromURL($doc_url,"_blank", 0, $args); //Set up the arguments for the PDF output $export_args = array($this->MakePropertyValue("FilterName","writer_pdf_Export",$osm)); //Write out the PDF $oWriterDoc->storeToURL($output_url,$export_args); $oWriterDoc->close(true); } public function test1() { $output_dir = SERVERBASE . 'client/files/proj_workaholic/office/pdf/'; $doc_file = SERVERBASE . 'client/files/proj_workaholic/office/office/helloWorld.doc'; $pdf_file = "hellowWorld.pdf"; $output_file = $output_dir . $pdf_file; // $doc_file = "file:///" . $doc_file; // $output_file = "file:///" . $output_file; $this->word2pdf($doc_file,$output_file); } test(); 系統:window xp
軟體:openoffice3.3
伺服器:xampp
php.ini - com.allow_dcom = true
錯誤:Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `com.sun.star.ServiceManager' in "the project of path"
------解決方案--------------------------------------------------------需要安裝OpenOffice.org
------解決方案-------------------------------------------------------- 1、檢查一下是否安裝過OpenOffice。
2、用命令行啟動OpenOffice服務:
cd C:\Program Files\OpenOffice.org 3\program
C:\Program Files\OpenOffice.org 3\program>soffice -headless -accept="socket,host然後再試驗一下呢.

8. php調用openoffice把office文件轉成html的問題

利用oppenoffice軟體轉換成html

9. php用openoffice轉換文檔到pdf為什麼有的文件可以有的不可以

看了下openoffice官方wiki和論壇貌似你得調節文件格式以及寬度等,過寬或者格式不對會造成空白文件或error。
https://wiki.openoffice.org/wiki/Documentation/OOo3_User_Guides/Getting_Started/Exporting_to_PDF

熱點內容
電腦上如何看wifi密碼 發布:2024-04-19 11:34:14 瀏覽:415
java性能測試腳本 發布:2024-04-19 11:25:24 瀏覽:980
存儲成本與性能 發布:2024-04-19 11:16:18 瀏覽:168
linux根文件系統製作 發布:2024-04-19 11:16:12 瀏覽:746
光遇夏日活動什麼時候安卓上線 發布:2024-04-19 11:08:15 瀏覽:854
Java開羅 發布:2024-04-19 10:50:55 瀏覽:959
linux音頻驅動 發布:2024-04-19 10:50:04 瀏覽:715
資料庫的表怎麼看 發布:2024-04-19 10:43:52 瀏覽:563
空調壓縮機不響 發布:2024-04-19 10:42:22 瀏覽:52
linux下的ftp工具 發布:2024-04-19 10:42:15 瀏覽:931