安裝插件 百度搜索javascript
調用css
//建立swf文件 第一個參數進入轉換的文件路徑 第二個參數輸出路徑的文件路徑 Office2Swf os = new Office2Swf("", main.getFileUrl()); os.officeToPdf();
配置文件 配置pdf2swf的路徑 以及文件輸出路徑html
LUCENE_PATH=D\:\\tomcat-7.0.55\\webapps\\PICCAssets\\uploadfile\\accept\\ PDF2SWF_PATH=D\:\\pdf2swf\\
Office2Swf 的具體實現java
package com.atsc.struts.valuesystem.dao; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.net.ConnectException; import java.util.PropertyResourceBundle; import com.artofsolving.jodconverter.DocumentConverter; import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter; import com.atsc.common.ConfigManager; public class Office2Swf { private String inputFile; private String outputFile; private String hpath; String fileName = ""; String pdfPath = ""; String LUCENE_PATH = ""; String pdf2swf = ""; public String getInputFile() { return inputFile; } public void setInputFile(String inputFile) { this.inputFile = inputFile; } public String getOutputFile() { return outputFile; } public void setOutputFile(String outputFile) { this.outputFile = outputFile; } /** * 初始化文件上傳路徑 以及 文件輸出路徑 * pdf2swf路徑 文件路徑LUCENE_PATH * @param inputFile * @param outputFile */ public Office2Swf(String inputFile, String outputFile) { this.inputFile = inputFile; this.outputFile = outputFile; PropertyResourceBundle configPic; try { configPic = new PropertyResourceBundle(ConfigManager.class.getClassLoader().getResourceAsStream("config.properties")); LUCENE_PATH = configPic.getString("LUCENE_PATH"); pdf2swf = configPic.getString("PDF2SWF_PATH"); } catch (IOException e1) { e1.printStackTrace(); } } /** * 轉化office文檔爲pdf * @throws FileNotFoundException */ public void officeToPdf() throws FileNotFoundException { String stroffice = outputFile.split("/")[2]; String hpath1 = getClass().getClassLoader().getResource("/").getPath(); String hpath2 = hpath1.replace("HTAssets", "upload").replace("WEB-INF", "uploadfile").replace("classes", "accept"); hpath = hpath2.substring(1); String strPdf = stroffice.substring(0, stroffice.lastIndexOf(".")) + ".pdf"; fileName = LUCENE_PATH + stroffice; pdfPath = LUCENE_PATH + strPdf; File inputF = new File(fileName); File outputF = new File(pdfPath); OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); try { connection.connect(); DocumentConverter converter = new OpenOfficeDocumentConverter(connection); converter.convert(inputF, outputF); System.out.println("轉化成功"); } catch (ConnectException e) { System.out.println("打開openoffice失敗"); e.printStackTrace(); } finally { connection.disconnect(); connection = null; } this.pdfToSwf(); } /** * 轉化pdf爲swf */ public void pdfToSwf() { String swfpath = pdfPath.substring(0, pdfPath.lastIndexOf(".")); System.out.println("轉化的SWF路徑:" + swfpath); try { Process p = Runtime.getRuntime().exec(pdf2swf + "pdf2swf.exe -o " + swfpath + ".swf -s flashversion=9 " + pdfPath); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); while (br.readLine() != null) { System.out.println("正在轉化swf中,請稍等。。。。。。。"); } } catch (IOException e) { System.out.println("讀取文件出現問題"); e.printStackTrace(); } finally { System.out.println("轉化swf完成"); } } }
頁面調用swf文件jquery
須要引入的flexpaper插件的jsweb
<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>tomcat
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <% String filename=request.getAttribute("filename").toString(); String hpath = (request.getAttribute("hpath").toString())+"upload/uploadfile/accept/"; out.write("<SCRIPT language="+"'"+"JavaScript"+"'"+">var filename="+"'"+filename+"'"+";var hpath="+"'"+hpath+"'"+";</SCRIPT>"); %> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <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> <style type="text/css" media="screen"> html,body { height: 100%; } body { margin: 0; padding: 0; overflow: auto; } #flashContent { display: none; } </style> <title>文檔在線預覽系統</title> </head> <body> <div style="position:absolute;left:50px;top:10px;"> <a id="viewerPlaceHolder" style="width:820px;height:650px;display:block"></a> <script type="text/javascript"> var fpath = "swfview/"+filename; var hpath = "http://192.168.1.10:8080/PICCAssets/uploadfile/accept/"; var fp = new FlexPaperViewer( 'FlexPaperViewer', 'viewerPlaceHolder', { config : { SwfFile : escape(hpath+filename), //SwfFile : escape("d:/swf"+filename), Scale : 1.2, ZoomTransition : 'easeOut', ZoomTime : 0.5, ZoomInterval : 0.2, FitPageOnLoad : true, FitWidthOnLoad : true, FullScreenAsMaxWindow : false, ProgressiveLoading : false, MinZoomSize : 0.2, MaxZoomSize : 5, SearchMatchAll : false, //InitViewMode : 'TwoPage', ViewModeToolsVisible : true, ZoomToolsVisible : true, NavToolsVisible : true, CursorToolsVisible : false, //SearchToolsVisible : true, localeChain: 'zh_CN' }}); </script> </div> </body> </html>