JAVA实现word、excel、ppt、txt等文件的在线预览

使用JAVA实现word、excel、ppt、txt在线预览功能

思路说明

通过第三方工具openoffice,将word、excel、ppt、txt等文件转换为pdf。获取pdf路径生成url从而实现在线预览功能。

使用office转换PDF

public static int officeToPDF(String sourceFile, String destFile) {
	try {
		File inputFile = new File(sourceFile);
		// 找不到源文件, 则返回-1
		if (!inputFile.exists()) {
			return -1;
		}

		// 如果目标路径不存在, 则新建该路径
		File outputFile = new File(destFile);
		// 如果该文件已经存在,则不再进行转换
	if (!outputFile.getParentFile().exists()) {
			outputFile.getParentFile().mkdirs();
		}
		// OpenOffice的安装目录
		String OpenOffice_HOME ="C:\\OpenOffice\\program\\soffice.exe ";
		// 启动OpenOffice的服务
		Process pro = Runtime.getRuntime().exec(OpenOffice_HOME);

		// connect to an OpenOffice.org instance running on port 8100
		OpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);
		connection.connect();

		// convert
		DocumentConverter 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值