灰儿 发表于 2015-8-14 15:23:32

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

基本步骤:    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都扔进来了       http://static.oschina.net/uploads/space/2014/0410/144408_NkUk_128886.png   首先、下载openOffice软件,并安装,使用dos命令开启服务   命令如下:?

1
<span>我安装在了 </span>C:\Program Files (x86)目录下






?

1
C:\Program Files (x86)\OpenOffice 4\program>soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard




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

1
2
3
4
5
6
7
8
9
10
11
12
13
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不生效。
?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 -T9 " ;      
         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
?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!--首先要引入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>




执行效果http://static.oschina.net/uploads/space/2014/0410/143818_lpSp_128886.png

页: [1]
查看完整版本: Java仿文库的基本方法(openoffice+swftools+flexPaper)