这篇文章主要为大家详细介绍了Java仿文库的基本方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
Java仿文库的基本方法
基本步骤:
1、将要展示的office文件 转换成 PDF, 使用工具 openoffice
2、将PDF文件转换成swf ,实用工具swftools
基础代码:没有任何校验
1、openoffice转换pdf
下载地址:https://www.openoffice.org/zh-cn/
实用工具: jodconverter-2.2.2 引入所需jar,直接将所有jar都扔进来了
首先、下载openOffice软件,并安装,使用dos命令开启服务,就是cmd了,我安装在了C盘
命令如下:执行效果
C:Program Files (x86)OpenOffice 4program>soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
File inputFile = new File("D:\大数据及应用.doc"); File outputFile = new File("D:\大数据及应用.pdf"); OpenOfficeConnection connection = new SocketopenOfficeConnection( "127.0.0.1", 8100); connection.connect(); // convert DocumentConverter converter = new OpenOfficeDocumentConverter( connection); converter.convert(inputFile, outputFile); // close the connection connection.disconnect();
2、swftools将PDF转换swf
下载地址:http://www.swftools.org/download.html
首先安装swftools工具,我是windows 下载exe文件,直接安装,
注:文件夹不要有空格,有空格不识别 如 program file 文件夹下 不好使
我安装在了D盘根目录下,该方法来源于网络,资料找的太多不记得从哪位大侠哪拷来得了,
还要注意下面代码被我改成windows的命令了,linux不生效。
public static int convertPDF2SWF(String sourcePath, String destPath, String fileName) throws IOException { //目标路径不存在则建立目标路径 File dest = new File(destPath); if (!dest.exists()) dest.mkdirs(); //源文件不存在则返回 File source = new File(sourcePath); if (!source.exists()) return 0; //调用pdf2swf命令进行转换 String command = "D:\SWFTools\pdf2swf.exe " + sourcePath + " -o " + destPath + fileName + " -f -T 9 " ; System.out.println(command); Process pro = Runtime.getRuntime().exec(command); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(pro.getInputStream())); while (bufferedReader.readLine() != null); try { pro.waitFor(); } catch (InterruptedException e) { // Todo Auto-generated catch block e.printstacktrace(); } return pro.exitValue(); }
4、flexPaper显示swf
下载地址:http://static.devaldi.com/GPL/FlexPaper_2.2.4.zip
jsp代码如下
该文件:FlexPaperViewer.swf
body内如下
执行效果: