技术标签: openoffice java web office
特点:
openoffice示例如下:
不需要部署、不需要编程,不需要做任何事情,只需要做个链接:点我预览,链接指向:
http://officeweb365.com/o/?i=您的网站ID&furl=要预览的Office文件下载地址
例:
1 不需要部署、不需要编程,不需要做任何事情,只需要做个链接:点我预览,链接指向: 2 http://officeweb365.com/o/?i=您的网站ID&furl=要预览的Office文件下载地址 3 例:<a href="http://officeweb365.com/o/?i=1&furl=http://a.com/downfile/a.doc" target="_blank">点我预览</a>
使用openOffice+swfTools+flexPaper实现文件预览功能的主要思想是:通过Java程序调用服务器上安装的软件openoffice,来将其它文件类型转化为pdf,然后调用swfTools将pdf转化为swf文件,在前端通过flexpaper插件来预览swf文件。
特点:
具体的实现可以参考下这个博客:OpenOffice+SwfTools+flexpaper实现文件预览
在我的项目中采用的就是这种方法,pdf.js的显示效果比较好,而且可以根据自己的项目需要完成相关的配置。下面说一下我的项目中具体使用:
查看运行的进程内有没有soffice.bin,有的话则启动成功。
jodconverter-2.2.2.jar
ridl-3.2.1.jar
commons.io.jar
juh.jar
jurt.jar
unoil.jar
slf4j-api-1.7.13.jarslf4j-jdk14-1.7.13.jarxstream-1.4.1.jar
1 package com.ams.util.server; 2 3 import java.io.BufferedInputStream; 4 import java.io.BufferedOutputStream; 5 import java.io.BufferedReader; 6 import java.io.File; 7 import java.io.FileInputStream; 8 import java.io.FileOutputStream; 9 import java.io.IOException; 10 import java.io.InputStream; 11 import java.io.InputStreamReader; 12 13 import com.artofsolving.jodconverter.DocumentConverter; 14 import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection; 15 import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection; 16 import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter; 17 18 public class DocConverter { 19 20 private String fileName; 21 private File pdfFile; 22 private File docFile; 23 private File odtFile; 24 25 26 27 public DocConverter(String sourceFile,String targetFile) throws Exception { 28 29 fileName = sourceFile.substring(0, sourceFile.lastIndexOf("/")); 30 docFile = new File(sourceFile);//得到转换前的文件 31 //得到文件的不带后缀的名字s 32 String s = sourceFile.substring(sourceFile.lastIndexOf("/") + 1,sourceFile.lastIndexOf(".")); 33 fileName = fileName + "/" + s; 34 // 用于处理TXT文档转化为PDF格式乱码,获取上传文件的名称(不需要后面的格式_ 35 String txtName = sourceFile.substring(sourceFile.lastIndexOf(".")); //得到文件格式 36 // 判断上传的文件是否是TXT文件 37 if (txtName.equalsIgnoreCase(".txt")) { 38 //是txt则需要转化为odt,然后再转为pdf 39 odtFile = new File(fileName + ".odt"); 40 // 将上传的文档重新copy丿份,并且修改为ODT格式,然后有ODT格式转化为PDF格式 41 this.copyFile(docFile, odtFile); 42 pdfFile = new File(targetFile); // 用于处理PDF文档 43 } else if (txtName.equals(".pdf") || txtName.equals(".PDF")) { 44 pdfFile = new File(targetFile); 45 this.copyFile(docFile, pdfFile); 46 } else{ 47 pdfFile = new File(targetFile); 48 } 49 doc2pdf();//调用函数进行转换 50 } 51 private void copyFile(File sourceFile,File targetFile)throws Exception{ 52 //新建文件输入流并对它进行缓冲 53 FileInputStream input = new FileInputStream(sourceFile); 54 BufferedInputStream inBuff = new BufferedInputStream(input); 55 // 新建文件输出流并对它进行缓冲 56 FileOutputStream output = new FileOutputStream(targetFile); 57 BufferedOutputStream outBuff = new BufferedOutputStream(output); 58 // 缓冲数组 59 byte[]b = new byte[1024 * 5]; 60 int len; 61 while((len = inBuff.read(b)) != -1){ 62 outBuff.write(b,0,len); 63 } 64 // 刷新此缓冲的输出浿 65 outBuff.flush(); 66 // 关闭流 67 inBuff.close(); 68 outBuff.close(); 69 output.close(); 70 input.close(); 71 } 72 private void doc2pdf() throws Exception { 73 if (docFile.exists()) { 74 if (!pdfFile.exists()) { 75 OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); 76 try { 77 connection.connect(); 78 DocumentConverter converter = new OpenOfficeDocumentConverter(connection); 79 converter.convert(docFile, pdfFile); 80 // close the connection 81 connection.disconnect(); 82 System.out.println("****pdf转换成功,PDF输出_" + pdfFile.getPath() + "****"); 83 } catch (java.net.ConnectException e) { 84 // ToDo Auto-generated catch block 85 e.printStackTrace(); 86 System.out.println("****swf转换异常,openoffice服务未启动!****"); 87 throw e; 88 } catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) { 89 e.printStackTrace(); 90 System.out.println("****swf转换器异常,读取转换文件失败****"); 91 throw e; 92 } catch (Exception e) { 93 e.printStackTrace(); 94 throw e; 95 } 96 } else { 97 System.out.println("****已经转换为pdf,不霿要再进行转化****"); 98 } 99 } else { 100 System.out.println("****swf转换器异常,霿要转换的文档不存在,无法转换****"); 101 } 102 }
103 }
以上就是我实现文件预览的几种方法,希望能和广大网友共同学习和进步!Fighting!
红黑树赛高,封装STL赛高!(有时候选择比努力更重要)代码:#include <bits/stdc++.h>using namespace std;typedef long long ll;multiset<int> ss;const int maxn = 200010;int a[maxn];int main(){ int t; cin ..._find the answer c++
测试环境:centos 6.6 zabbix-2.4.8 1、下载zabbixwget https://ncu.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.4.8/zabbix-2.4.8.tar.gz2、解压tar -zxvf zabbix-2.4.8.tar.gz 3、_zabbix客户端安装 linux
UE4利用材质控制模型扭曲变形一、小白人变色二、其他人物变身参考视频链接:https://www.bilibili.com/video/BV1bb411b7YZ/?spm_id_from=333.788.videocard.4一、小白人变色1、新建材质函数,命名为MF_Transform,Blend Mode选择Opaque2、新建材质M_Transform3、创建材质实例M_Tra..._ue4光圈会变形
DC-6靶机渗透测试详细教程_dc-6
俗话说,隔行如隔山,异步君的朋友曾天真地问我桌面上花花绿绿的“字母”是什么?当我告诉她,没有这些“字母”,就没有她每天看的微博热搜和小哥哥美照。她:“???”把代码理解为“字母”是外行闹笑话,那同行是不是就能理解彼此?其实不然,对程序员来说,最痛苦的事情不是修BUG,看其他人写的代码更痛苦。特别是看没注释的代码,恨不得给同事一招乾坤大挪移,把他写代码时的脑子,移给自己。“没注释的代码就像小..._程序员你命名数字习惯
首先,两个函数的功能是有区别的:reserve是容器预留空间,但并不真正创建元素对象,在创建对象之前,不能引用容器内的元素,因此当加入新的元素时,需要用push_back()/insert()函数。resize是改变容器的大小,并且创建对象,因此,调用这个函数之后,就可以引用容器内的对象了,因此当加入新的元素时,用operator[]操作符,或者用迭代器来引用元素对象。其次,两个函数的形式是有区别的:reserve函数之后一个参数,即需要预留的容器的空间;resize函数可以有两个参数,第一个_回答 下 stl resize 和 reserve 的区别
Every day the citizens of the Internet send each other billions of e-mail messages. If you are online a lot, you yourself may send a dozen or two e-mails
Android 使用RadioGroup 实现底部导航菜单栏。一、主界面布局的实现: 先来张效果图: 介绍一下总体界面包括的内容:底部五个导航按钮,主界面包括一个FrameLayout用来放五个Fragment。点击底部按钮会对应跳转到指定的界面。 实现布局:activity_main.xml<?xml version="1.0" encoding="utf-_安卓底部菜单栏的实现</div>
Part 1:“离散化”是什么嘞?先介绍一下离散化 桶排大家应该知道,就是开一个数组(下标为数值,记录了该数值的出现次数)然后遍历过去如果出现次数不为零,那就输出这些数字,理论时间复杂度可以达到O(N)但是由于内存限制,不能开很大的数组。然而 如果某个数列中的数字不要求大小确定,只要求这些数字有相对的大小就够了的话,离散化就有了用武之地(换言之,如果一个数的大小在1e9上下,那我们可以用离散化..._离散型数据赋权值
python3下无法安装PIL。提示报错。正确的做法是安装PIL的模块Pillow。输入命令pip installPillow提示安装成功,再运行程序没有问题
一个简易实用物流信息跟踪页面模板,套上即可使用,可支持个人实际情况需求修改。话不多说,直接上代码示例哦= =基于vue2.0版的uniapp使用代码示例(ps:毕竟vue3.0了)template结构模块:引入插件模块引入组件模块函数方法:data函数模块:(截图一半)数据json模板使用快递100快递100相关技术文档地址: https://api.kuaidi100.com/document/5f0ffa8f2977d50a94e1023c.html#title_1._后端物流跟踪模块
stringpostString="arg1=a&arg2=b";//这里即为传递的参数,可以用工具抓包分析,也可以自己分析,主要是form里面每一个name都要加进来byte[]postData=Encoding.UTF8.GetBytes(postString);//编码,尤其是汉字,事先要看下抓取网页的编码方式stringurl="http://...