摘要 仿百度文庫的基本功能,寫的比較粗糙,只記錄基本過程和步驟javascript
基本步驟:html
一、將要展現的office文件 轉換成 PDF, 使用工具 openoffice 二、將PDF文件轉換成swf ,實用工具swftools 三、使用flexPaper,顯示轉換後的swf文件。
基礎代碼:沒有任何校驗java
一、openoffice轉換pdf 下載地址:https://www.openoffice.org/zh-cn/ 實用工具: jodconverter-2.2.2 引入所需jar,直接將全部jar都扔進來了 首先、下載openOffice軟件,並安裝,使用dos命令開啓服務 命令以下:
我安裝在了 C:\Program Files (x86) 目錄下jquery
C:\Program Files (x86)\OpenOffice 4\program>soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizardlinux
啓動後,執行如下命令 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();windows
// convert
DocumentConverter converter = new OpenOfficeDocumentConverter( connection); converter.convert(inputFile, outputFile);網絡
// close the connection connection.disconnect();less
二、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();
}socket
四、flexPaper顯示swf 下載地址:http://static.devaldi.com/GPL/FlexPaper_2.2.4.zip jsp代碼以下 該文件:FlexPaperViewer.swf
<!--首先要引入jquery庫及相關的js 下載包裏面 找-->jsp
<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>
執行效果