首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > PowerDesigner >

利用OpenOffice对html、word、pdf进展转换

2012-07-15 
利用OpenOffice对html、word、pdf进行转换??public class OpenOfficeService {private Logger logger Logg

利用OpenOffice对html、word、pdf进行转换


?

?

public class OpenOfficeService {private Logger logger = Logger.getLogger(this.getClass());OpenOfficeConnection con = null;public void convert(File sourceFile, File _targetFile) {try {if (con == null) {con = new SocketOpenOfficeConnection(ip, port);}con.connect();DocumentConverter converter = new OpenOfficeDocumentConverter(con);converter.convert(sourceFile, _targetFile);// DefaultDocumentFormatRegistry formatReg = new DefaultDocumentFormatRegistry();// converter.convert(sourceFile, formatReg.getFormatByFileExtension("html"), _targetFile, formatReg.getFormatByFileExtension("pdf"));} catch (ConnectException e) {logger.error("OpenOffice异常", e);try {if (con != null) {con.disconnect();con = null;}} catch (Exception e1) {logger.error(e);}}}public static void main(String[] args) {OpenOfficeService openoffice = new OpenOfficeService();// 生成odt,本质上可以用word打开(可以在下载时修改为doc文件,以屏蔽用户感觉到的差异),如果生成doc,则图片会丢失openoffice.convert(new File("WebRoot/jsp/data/docs/a.html"), new File("WebRoot/jsp/data/docs/a.odt"));// 生成pdfopenoffice.convert(new File("WebRoot/jsp/data/docs/a.html"), new File("WebRoot/jsp/data/docs/a.pdf"));}public void setIp(String ip) {this.ip = ip;}public void setPort(int port) {this.port = port;}private String ip = "127.0.0.1";private int port = 8100;}
?过程中遇到的问题

html中的图片可以转化到pdf,但是在不能转化到word中,经测试可以转化到odt文件中,所以我在开发过程中实际上是由hmt转换为odt,再在下载的过程中将后缀改为doc格式,另外,html中的图片,最好与html文件放到同一目录下,引用方式为相对目录,也可以修改html的图片路径为绝对路径。

1 楼 bluerose 2012-05-04   大哥  中文是乱码 我在windows下
请问你遇到了么 怎么解决的 谢谢 2 楼 zhang_637 2012-05-14   bluerose 写道大哥  中文是乱码 我在windows下
请问你遇到了么 怎么解决的 谢谢
没有遇到,不知道你的源文件编码是否是本地编码?

热点排行