基本步驟:
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
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 -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
1
2
3
4
|
<!--首先要引入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內如下
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
|
< 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 > |
執行效果:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。