Java仿文库的基本方法openoffice+swftools+flexPaper

这篇文章主要为大家详细介绍了Java仿文库的基本方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

Java仿文库的基本方法

基本步骤:

    1、将要展示的office文件 转换成 PDF,  使用工具 openoffice 

    2、将PDF文件转换成swf ,实用工具swftools

    3、使用flexPaper,显示转换后的swf文件

基础代码没有任何校验

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 

启动后,执行以下命令    doc文件为原始文件,转换成pdf

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内如下  

执行效果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

相关文章

HashMap是Java中最常用的集合类框架,也是Java语言中非常典型...
在EffectiveJava中的第 36条中建议 用 EnumSet 替代位字段,...
介绍 注解是JDK1.5版本开始引入的一个特性,用于对代码进行说...
介绍 LinkedList同时实现了List接口和Deque接口,也就是说它...
介绍 TreeSet和TreeMap在Java里有着相同的实现,前者仅仅是对...
HashMap为什么线程不安全 put的不安全 由于多线程对HashMap进...