乔山办公网我们一直在努力
您的位置:乔山办公网 > office365 > openoffice 支持把哪些格式转成html,pdf可以...

openoffice 支持把哪些格式转成html,pdf可以...

作者:乔山办公网日期:

返回目录:office365


你需要几下载几个包,然后安装配置一下:
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 &

开机e68a84e799bee5baa6366启动:
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

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包。

8、Coding...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

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连接e79fa5e98193e59b9ee7ad94333
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;
}

}
你把openoffice安装到了c:\program files目录中去,这个目录带有空格,导致命令字符串出现歧义,让java把c:\program当成可执行文件。微软的这个带空格的目录真是麻烦!
用引号把soffice.exe与路径括起来试一试
或者设置好PATH环境变量。

1、下载OpenOffice,http://download.openoffice.org/index.html So easy...

2、下载Jodconverter http:///opensource/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包。

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|e799bee5baa6e997aee7ad94e78988e69d83333FONT|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;
    }

}

参考:http:///codeplus/archive/2011/10/22/2220952.html

相关阅读

  • word转成PDF时,怎么让pdf自动生成<em>书签</em>

  • 乔山办公网office365
  • wps转换成PDF图不在了,这是因为WPS并不是可以百分百兼容office所致的。倒不如用专业来的转换工具效果更好。wps转成PDF文件自方法:1、 使用官方的adobe acrobat 软件可以将word、excel等等转
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网