您的位置:首页 > 编程语言 > Java开发

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

2016-05-19 10:41 423 查看
基本步骤:

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 4\program>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
<!--首先要引入jquery库及相关的js   下载包里面 找-->
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/flexpaper_flash.js"></script>
<script type="text/javascript" src="js/flexpaper_flash_debug.js"></script>

body内如下
<div style="position:absolute;left:10px;top:10px;">
<a id="viewerPlaceHolder" style="width:1260px;height:780px;display:block"></a>
<script type="text/javascript">
var fp = new FlexPaperViewer(
'FlexPaperViewer',
'viewerPlaceHolder',     <!--对应于a 标签的id-->
{ config : {
SwfFile :  decodeURI('aaa.swf'),  <!--引入的swf文件,decodeURI 解决中文文件名问题-->
Scale : 0.6,
ZoomTransition : 'easeOut',
ZoomTime : 0.5,
ZoomInterval : 0.2,
FitPageOnLoad : true,
FitWidthOnLoad : false,
PrintEnabled : true,
FullScreenAsMaxWindow : false,
ProgressiveLoading : false,
MinZoomSize : 0.2,
MaxZoomSize : 5,
SearchMatchAll : false,
InitViewMode : 'Portrait',

ViewModeToolsVisible : true,
ZoomToolsVisible : true,
NavToolsVisible : true,
CursorToolsVisible : true,
SearchToolsVisible : true,
localeChain: 'zh_CN'   <!--改成这个显示中文-->
}});
</script>
</div>


执行效果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: