当前位置:首页 » 编程语言 » 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

热点内容
安卓手机软件如何快速打开 发布:2024-05-02 13:25:16 浏览:962
安卓网页图片不显示怎么办 发布:2024-05-02 13:16:00 浏览:673
虚拟机搭建linux 发布:2024-05-02 13:02:48 浏览:186
哈弗f7配置怎么使用 发布:2024-05-02 12:53:14 浏览:575
psv重新构建数据库 发布:2024-05-02 12:43:53 浏览:792
农行对公密码器的凭证号码在哪里 发布:2024-05-02 12:38:55 浏览:890
双子星脚本 发布:2024-05-02 12:26:01 浏览:142
域名如何将程序部署到服务器 发布:2024-05-02 12:25:38 浏览:948
命令行编译lex 发布:2024-05-02 12:17:25 浏览:61
linux读u盘 发布:2024-05-02 11:49:37 浏览:782