Office2PDF

思路

Office2SWF文件转换分为两个步骤,一为Office转换为PDF文件,二为PDF文件转换为SWF文件。

必需工具

1.下载OpenOffice.org
  OpenOffice.org 是一套跨平台的办公室软件套件,能在Windows、Linux、MacOS X (X11)和 Solaris 等操作系统上执行。主要它是免费的。
  
OpenOffice.org下载地址  http://www.openoffice.org/download/

在这里插入图片描述
下载了NNNNN年后,果然还没完成。删了重新找资源。
在这位大佬下的资源   感谢这位大佬!!!!!!!!!!!!!  
https://download.youkuaiyun.com/download/rcl_642263983/10633351

继续安装。。。。。。
安装成功后,启动openOffice服务(这里只介绍手动版)
启动服务方式一:
找到你的安装路径里面的 program 文件下
在这里插入图片描述
操作:
按住shift键+鼠标右键 在此处打开命令窗口
输入:soffice -headless -accept=“socket,host=127.0.0.1,port=8100;urp;” -nofirststartwizard

启动服务方式二:
操作:
打开cmd 输入
cd: 安装路径+soffice -headless -accept=“socket,host=127.0.0.1,port=8100;urp;” -nofirststartwizard
例如:
cd D:\openOffice\program soffice -headless -accept=“socket,host=127.0.0.1,port=8100;urp;” -nofirststartwizard

启动后,查看8100端口
cmd 输入 netstat -ano|findstr “8100” 看是否存在8100端口

2.下载jodconverter2.2.2 所有的资源包

官网资源 https://sourceforge.net/projects/jodconverter/
csdn资源 https://download.youkuaiyun.com/download/END_Loving/12089119

代码部分

创建class DOC2PDFUtil工具类

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;

public class DOC2PDFUtil extends Thread {
	private File inputFile;// 需要转换的文件
	private File outputFile;// 输出的文件

	public DOC2PDFUtil(File inputFile, File outputFile) {
		this.inputFile = inputFile;
		this.outputFile = outputFile;
	}
	public void docToPdf() {
		OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
		try {
			connection.connect();
			DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
			converter.convert(inputFile, outputFile);
		} catch (ConnectException cex) {
			cex.printStackTrace();
		} finally {
			// close the connection
			if (connection != null) {
				connection.disconnect();
				connection = null;
			}
		}
	}
	/**  
	  * 服务的线程不安全的
	   */
	public void run() {
		this.docToPdf();
	}
	public File getInputFile() {
		return inputFile;
	}
	public void setInputFile(File inputFile) {
		this.inputFile = inputFile;
	}
	public File getOutputFile() {
		return outputFile;
	}
	public void setOutputFile(File outputFile) {
		this.outputFile = outputFile;
	}
}

controller代码

@RequestMapping(value = "/addSWF")
	public JtsResult addIndex(HttpServletRequest request, HttpServletResponse response) throws IOException {
	//文件的绝对路径
	File inputFile = new File("C:\\Users\\HASEE\\Desktop\\jts-doc\\swf\\cs.pptx");
	//文件的输出路径
	File outputFile = new File("C:\\Users\\HASEE\\Desktop\\jts-doc\\swf\\cs.pdf");
	DOC2PDFUtil dp = new DOC2PDFUtil(inputFile, outputFile);
	dp.start();
}

在这里插入图片描述

测试

优点
windows和linux环境都可以实现转换
ppt 、pptx、doc、docx、xls、xlsx格式都支持转换

缺点
word文件中的部分格式转换不了。visio图片转换不了、数学公式 转换不了。
如果文档里面的格式很复杂。最好寻找其他资源实现。因为我转换的文件里面存在数学公式。所以放弃使用openoffice+jodconverter实现office文件转换pdf。
如果有大佬发现在windows和linux环境下可以转换实现office转换成swf格式和文件(支持比较复杂的格式,例如:数学公式和visio图片格式),求指导下。感谢!!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值