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内如下
执行效果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



