java實現附件預覽(openoffice+swftools+flexpaper)

1、概述

    1.1 主要原理:

         1.通過第三方工具openoffice,將word、excel、ppt、txt等文件轉換爲pdf文件

         2.通過swfTools將pdf文件轉換成swf格式的文件

         3.通過FlexPaper文檔組件在頁面上進行展示

    1.2 安裝包下載

1.openoffice是Apache下的一個開放免費的文字處理軟件

   下載地址:Apache oppenoffice  官網下載 版本-3.4.1

2.SWFTools是一組用來處理Flash的swf文件的工具包,我們使用它將pdf文件轉成swf文件!

   下載地址:SWFTools官網下載 swftools-2013-04-09-1007.exe

3.FlexPaper是一個開源輕量級的在瀏覽器上顯示各種文檔的組件

   下載地址:FlexPaper官網下載 版本1.5.1

4.JODConverter一個Java的OpenDocument 文件轉換器,該工具包會用到調用openoffice,實現word、excel、ppt、txt等文件轉換爲pdf文件。在此我們只用到它的jar包。

   下載地址:JODCConverter下載

   1.3 安裝文件

1.將所下載的文件(JODConverter除外)進行安裝,盤符可隨自己設定!需要注意的是在openoffice安裝完成後,當我們使用它時,需將它的服務打開。在次我們需要以命令的方式打開:

打開dos窗口,進入openoffice安裝盤符,輸入以下代碼來啓動服務:

soffice -headless -accept=”socket,host=127.0.0.1,port=8100;urp;” -nofirststartwizard

注意最後一個命令前邊的‘—’,可不要寫錯!服務起不來,項目可是繼續不下去的哦.

官網啓動服務截圖如下:

本地截圖:

 

2、開發過程

        2.1 新建項目

        將flexpaper文件中的js文件夾(包含了flexpaper_flash_debug.js,flexpaper_flash.js,jquery.js,這三個js文件主要是預覽swf文件的插件)拷貝至網站根目錄;將FlexPaperViewer.swf拷貝至網站根目錄下(該文件主要是用在網頁中播放swf文件的播放器),目錄結構如下圖:

注:需創建upload文件夾      

        2.2 創建fileUpload.jsp

  1. <%@ page language=“java” contentType=“text/html; charset=UTF-8” pageEncoding=“UTF-8”%>
  2. <!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
  3. <html>
  4. <head>
  5. <meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8”>
  6. <title>文檔在線預覽系統</title>
  7. <style>
  8. body {margin-top:100px;background:#fff;font-family: Verdana, Tahoma;}
  9. a {color:#CE4614;}
  10. #msg-box {color: #CE4614; font-size:0.9em;text-align:center;}
  11. #msg-box .logo {border-bottom:5px solid #ECE5D9;margin-bottom:20px;padding-bottom:10px;}
  12. #msg-box .title {font-size:1.4em;font-weight:bold;margin:0 0 30px 0;}
  13. #msg-box .nav {margin-top:20px;}
  14. </style>
  15. </head>
  16. <body>
  17. <div id=“msg-box”>
  18. <form name=“form1” method=“post” enctype=“multipart/form-data” action=“docUploadConvertAction.jsp”>
  19. <div class=“title”>
  20. 請上傳要處理的文件,過程可能需要幾分鐘,請稍候片刻。
  21. </div>
  22. <p>
  23. <input name=“file1” type=“file”>
  24. </p>
  25. <p>
  26. <input type=“submit” name=“Submit” value=“上傳”>
  27. </p>
  28. </form >
  29. </div>
  30. </body>
  31. </html>

        2.3 創建轉換頁docUploadConvertAction.jsp

  1. 01.<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
  2. 02.
  3. 03.<%@page import="java.io.*"%>
  4. 04.<%@page import="java.util.Enumeration"%>
  5. 05.<%@page import="com.oreilly.servlet.MultipartRequest"%>
  6. 06.<%@page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy"%>
  7. 07.<%@page import="com.cectsims.util.DocConverter"%>
  8. 08.<%
  9. 09.//文件上傳採用cos組件上傳,可更換爲commons-fileupload上傳,文件上傳後,保存在upload文件夾
  10. 10.//獲取文件上傳路徑
  11. 11.String saveDirectory =application.getRealPath("/")+"upload";
  12. 12.//打印上傳路徑信息
  13. 13.System.out.println(saveDirectory);
  14. 14.//每個文件最大50m
  15. 15.int maxPostSize = 50 * 1024 * 1024 ;
  16. 16.//採用cos缺省的命名策略,重名後加1,2,3...如果不加dfp重名將覆蓋
  17. 17.DefaultFileRenamePolicy dfp = new DefaultFileRenamePolicy();
  18. 18.//response的編碼爲"UTF-8",同時採用缺省的文件名衝突解決策略,實現上傳,如果不加dfp重名將覆蓋
  19. 19.MultipartRequest multi = new MultipartRequest(request, saveDirectory, maxPostSize,"UTF-8",dfp);
  20. 20.//MultipartRequest multi = new MultipartRequest(request, saveDirectory, maxPostSize,"UTF-8");
  21. 21.//輸出反饋信息
  22. 22. Enumeration files = multi.getFileNames();
  23. 23. while (files.hasMoreElements()) {
  24. 24. System.err.println("ccc");
  25. 25. String name = (String)files.nextElement();
  26. 26. File f = multi.getFile(name);
  27. 27. if(f!=null){
  28. 28. String fileName = multi.getFilesystemName(name);
  29. 29. //獲取上傳文件的擴展名
  30. 30. String extName=fileName.substring(fileName.lastIndexOf(".")+1);
  31. 31. //文件全路徑
  32. 32. String lastFileName= saveDirectory+"\\" + fileName;
  33. 33. //獲取需要轉換的文件名,將路徑名中的'\'替換爲'/'
  34. 34. String converfilename = saveDirectory.replaceAll("\\\\", "/")+"/"+fileName;
  35. 35. System.out.println(converfilename);
  36. 36. //調用轉換類DocConverter,並將需要轉換的文件傳遞給該類的構造方法
  37. 37. DocConverter d = new DocConverter(converfilename);
  38. 38. //調用conver方法開始轉換,先執行doc2pdf()將office文件轉換爲pdf;再執行pdf2swf()將pdf轉換爲swf;
  39. 39. d.conver();
  40. 40. //調用getswfPath()方法,打印轉換後的swf文件路徑
  41. 41. System.out.println(d.getswfPath());
  42. 42. //生成swf相對路徑,以便傳遞給flexpaper播放器
  43. 43. String swfpath = "upload"+d.getswfPath().substring(d.getswfPath().lastIndexOf("/"));
  44. 44. System.out.println(swfpath);
  45. 45. //將相對路徑放入sessio中保存
  46. 46. session.setAttribute("swfpath", swfpath);
  47. 47. out.println("上傳的文件:"+lastFileName);
  48. 48. out.println("文件類型"+extName);
  49. 49. out.println("<hr>");
  50. 50. }
  51. 51. }
  52. 52.
  53. 53.%>
  54. 54.<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  55. 55.<html>
  56. 56.<head>
  57. 57.<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  58. 58.<title>Insert title here</title>
  59. 59.<style>
  60. 60. body {margin-top:100px;background:#fff;font-family: Verdana, Tahoma;}
  61. 61. a {color:#CE4614;}
  62. 62. #msg-box {color: #CE4614; font-size:0.9em;text-align:center;}
  63. 63. #msg-box .logo {border-bottom:5px solid #ECE5D9;margin-bottom:20px;padding-bottom:10px;}
  64. 64. #msg-box .title {font-size:1.4em;font-weight:bold;margin:0 0 30px 0;}
  65. 65. #msg-box .nav {margin-top:20px;}
  66. 66.</style>
  67. 67.</head>
  68. 68.<body>
  69. 69. <div>
  70. 70. <form name="viewForm" id="form_swf" action="documentView.jsp" method="POST">
  71. 71. <input type='submit' value='預覽' class='BUTTON SUBMIT'/>
  72. 72. </form>
  73. 73. </div>
  74. 74.</body>
  75. 75.</html>

        2.4 創建查看頁documentView.jsp

  1. 01.<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
  2. 02.<%
  3. 03. String swfFilePath=session.getAttribute("swfpath").toString();
  4. 04.%>
  5. 05.<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  6. 06.<html>
  7. 07.<head>
  8. 08.<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9. 09.<script type="text/javascript" src="js/jquery.js"></script>
  10. 10.<script type="text/javascript" src="js/flexpaper_flash.js"></script>
  11. 11.<script type="text/javascript" src="js/flexpaper_flash_debug.js"></script>
  12. 12.<style type="text/css" media="screen">
  13. 13. html, body { height:100%; }
  14. 14. body { margin:0; padding:0; overflow:auto; }
  15. 15. #flashContent { display:none; }
  16. 16. </style>
  17. 17.
  18. 18.<title>文檔在線預覽系統</title>
  19. 19.</head>
  20. 20.<body>
  21. 21. <div style="position:absolute;left:50px;top:10px;">
  22. 22. <a id="viewerPlaceHolder" style="width:820px;height:650px;display:block"></a>
  23. 23.
  24. 24. <script type="text/javascript">
  25. 25. var fp = new FlexPaperViewer(
  26. 26. 'FlexPaperViewer',
  27. 27. 'viewerPlaceHolder', { config : {
  28. 28. SwfFile : escape('<%=swfFilePath%>'),
  29. 29. Scale : 0.6,
  30. 30. ZoomTransition : 'easeOut',
  31. 31. ZoomTime : 0.5,
  32. 32. ZoomInterval : 0.2,
  33. 33. FitPageOnLoad : true,
  34. 34. FitWidthOnLoad : false,
  35. 35. FullScreenAsMaxWindow : false,
  36. 36. ProgressiveLoading : false,
  37. 37. MinZoomSize : 0.2,
  38. 38. MaxZoomSize : 5,
  39. 39. SearchMatchAll : false,
  40. 40. InitViewMode : 'SinglePage',
  41. 41.
  42. 42. ViewModeToolsVisible : true,
  43. 43. ZoomToolsVisible : true,
  44. 44. NavToolsVisible : true,
  45. 45. CursorToolsVisible : true,
  46. 46. SearchToolsVisible : true,
  47. 47.
  48. 48. localeChain: 'en_US'
  49. 49. }});
  50. 50. </script>
  51. 51. </div>
  52. 52.</body>
  53. 53.</html>

        2.5 創建轉換類DocConverter.java

  1. 01.package com.cectsims.util;
  2. 02.import java.io.BufferedInputStream;
  3. 03.import java.io.File;
  4. 04.import java.io.IOException;
  5. 05.import java.io.InputStream;
  6. 06.
  7. 07.import com.artofsolving.jodconverter.DocumentConverter;
  8. 08.import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
  9. 09.import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
  10. 10.import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
  11. 11.
  12. 12./**
  13. 13. * doc docx格式轉換
  14. 14. */
  15. 15.public class DocConverter {
  16. 16. private static final int environment = 1;// 環境 1:windows 2:linux
  17. 17. private String fileString;// (只涉及pdf2swf路徑問題)
  18. 18. private String outputPath = "";// 輸入路徑 ,如果不設置就輸出在默認的位置
  19. 19. private String fileName;
  20. 20. private File pdfFile;
  21. 21. private File swfFile;
  22. 22. private File docFile;
  23. 23.
  24. 24. public DocConverter(String fileString) {
  25. 25. ini(fileString);
  26. 26. }
  27. 27.
  28. 28. /**
  29. 29. * 重新設置file
  30. 30. *
  31. 31. * @param fileString
  32. 32. */
  33. 33. public void setFile(String fileString) {
  34. 34. ini(fileString);
  35. 35. }
  36. 36.
  37. 37. /**
  38. 38. * 初始化
  39. 39. *
  40. 40. * @param fileString
  41. 41. */
  42. 42. private void ini(String fileString) {
  43. 43. this.fileString = fileString;
  44. 44. fileName = fileString.substring(0, fileString.lastIndexOf("."));
  45. 45. docFile = new File(fileString);
  46. 46. pdfFile = new File(fileName + ".pdf");
  47. 47. swfFile = new File(fileName + ".swf");
  48. 48. }
  49. 49.
  50. 50. /**
  51. 51. * 轉爲PDF
  52. 52. *
  53. 53. * @param file
  54. 54. */
  55. 55. private void doc2pdf() throws Exception {
  56. 56. if (docFile.exists()) {
  57. 57. if (!pdfFile.exists()) {
  58. 58. OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
  59. 59. try {
  60. 60. connection.connect();
  61. 61. DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
  62. 62. converter.convert(docFile, pdfFile);
  63. 63. // close the connection
  64. 64. connection.disconnect();
  65. 65. System.out.println("****pdf轉換成功,PDF輸出:" + pdfFile.getPath()+ "****");
  66. 66. } catch (java.net.ConnectException e) {
  67. 67. e.printStackTrace();
  68. 68. System.out.println("****swf轉換器異常,openoffice服務未啓動!****");
  69. 69. throw e;
  70. 70. } catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) {
  71. 71. e.printStackTrace();
  72. 72. System.out.println("****swf轉換器異常,讀取轉換文件失敗****");
  73. 73. throw e;
  74. 74. } catch (Exception e) {
  75. 75. e.printStackTrace();
  76. 76. throw e;
  77. 77. }
  78. 78. } else {
  79. 79. System.out.println("****已經轉換爲pdf,不需要再進行轉化****");
  80. 80. }
  81. 81. } else {
  82. 82. System.out.println("****swf轉換器異常,需要轉換的文檔不存在,無法轉換****");
  83. 83. }
  84. 84. }
  85. 85.
  86. 86. /**
  87. 87. * 轉換成 swf
  88. 88. */
  89. 89. @SuppressWarnings("unused")
  90. 90. private void pdf2swf() throws Exception {
  91. 91. Runtime r = Runtime.getRuntime();
  92. 92. if (!swfFile.exists()) {
  93. 93. if (pdfFile.exists()) {
  94. 94. if (environment == 1) {// windows環境處理
  95. 95. try {
  96. 96. Process p = r.exec("D:/Program Files/SWFTools/pdf2swf.exe "+ pdfFile.getPath() + " -o "+ swfFile.getPath() + " -T 9");
  97. 97. System.out.print(loadStream(p.getInputStream()));
  98. 98. System.err.print(loadStream(p.getErrorStream()));
  99. 99. System.out.print(loadStream(p.getInputStream()));
  100. 100. System.err.println("****swf轉換成功,文件輸出:"
  101. 101. + swfFile.getPath() + "****");
  102. 102. if (pdfFile.exists()) {
  103. 103. pdfFile.delete();
  104. 104. }
  105. 105.
  106. 106. } catch (IOException e) {
  107. 107. e.printStackTrace();
  108. 108. throw e;
  109. 109. }
  110. 110. } else if (environment == 2) {// linux環境處理
  111. 111. try {
  112. 112. Process p = r.exec("pdf2swf " + pdfFile.getPath()
  113. 113. + " -o " + swfFile.getPath() + " -T 9");
  114. 114. System.out.print(loadStream(p.getInputStream()));
  115. 115. System.err.print(loadStream(p.getErrorStream()));
  116. 116. System.err.println("****swf轉換成功,文件輸出:"
  117. 117. + swfFile.getPath() + "****");
  118. 118. if (pdfFile.exists()) {
  119. 119. pdfFile.delete();
  120. 120. }
  121. 121. } catch (Exception e) {
  122. 122. e.printStackTrace();
  123. 123. throw e;
  124. 124. }
  125. 125. }
  126. 126. } else {
  127. 127. System.out.println("****pdf不存在,無法轉換****");
  128. 128. }
  129. 129. } else {
  130. 130. System.out.println("****swf已經存在不需要轉換****");
  131. 131. }
  132. 132. }
  133. 133.
  134. 134. static String loadStream(InputStream in) throws IOException {
  135. 135.
  136. 136. int ptr = 0;
  137. 137. in = new BufferedInputStream(in);
  138. 138. StringBuffer buffer = new StringBuffer();
  139. 139.
  140. 140. while ((ptr = in.read()) != -1) {
  141. 141. buffer.append((char) ptr);
  142. 142. }
  143. 143.
  144. 144. return buffer.toString();
  145. 145. }
  146. 146. /**
  147. 147. * 轉換主方法
  148. 148. */
  149. 149. @SuppressWarnings("unused")
  150. 150. public boolean conver() {
  151. 151.
  152. 152. if (swfFile.exists()) {
  153. 153. System.out.println("****swf轉換器開始工作,該文件已經轉換爲swf****");
  154. 154. return true;
  155. 155. }
  156. 156.
  157. 157. if (environment == 1) {
  158. 158. System.out.println("****swf轉換器開始工作,當前設置運行環境windows****");
  159. 159. } else {
  160. 160. System.out.println("****swf轉換器開始工作,當前設置運行環境linux****");
  161. 161. }
  162. 162. try {
  163. 163. doc2pdf();
  164. 164. pdf2swf();
  165. 165. } catch (Exception e) {
  166. 166. e.printStackTrace();
  167. 167. return false;
  168. 168. }
  169. 169.
  170. 170. if (swfFile.exists()) {
  171. 171. return true;
  172. 172. } else {
  173. 173. return false;
  174. 174. }
  175. 175. }
  176. 176.
  177. 177. /**
  178. 178. * 返回文件路徑
  179. 179. *
  180. 180. * @param s
  181. 181. */
  182. 182. public String getswfPath() {
  183. 183. if (swfFile.exists()) {
  184. 184. String tempString = swfFile.getPath();
  185. 185. tempString = tempString.replaceAll("\\\\", "/");
  186. 186. return tempString;
  187. 187. } else {
  188. 188. return "";
  189. 189. }
  190. 190.
  191. 191. }
  192. 192. /**
  193. 193. * 設置輸出路徑
  194. 194. */
  195. 195. public void setOutputPath(String outputPath) {
  196. 196. this.outputPath = outputPath;
  197. 197. if (!outputPath.equals("")) {
  198. 198. String realName = fileName.substring(fileName.lastIndexOf("/"),
  199. 199. fileName.lastIndexOf("."));
  200. 200. if (outputPath.charAt(outputPath.length()) == '/') {
  201. 201. swfFile = new File(outputPath + realName + ".swf");
  202. 202. } else {
  203. 203. swfFile = new File(outputPath + realName + ".swf");
  204. 204. }
  205. 205. }
  206. 206. }
  207. 207.
  208. 208.}

        2.6 部署發佈

        啓動tomcat,部署當前web應用
        地址欄輸入http://localhost:8080/ctcesims/documentUpload.jsp 如下圖:


單擊選擇文件,選擇您要上傳的文檔,然後單擊上傳,處理完成後,打印如下信息,如下圖所示:


單擊預覽按鈕,就會生成預覽界面,如下圖:



4.常見問題

       若出現swf無法預覽,請訪問:http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html#119065

將生成swf的文件夾設置爲信任文件位置。
        以下給出 flexpaper 2.1.9 的不同之處:初始化方式改變,若文件目錄與項目目錄不在一起,可將附件目錄在服務器中設置爲虛擬目錄

  1. 1.<%@ page language="java" contentType="text/html; charset=UTF-8"
  2. 2. pageEncoding="UTF-8"%>
  3. 3.<%
  4. 4. //String swfFilePath=session.getAttribute("swfpath").toString();
  5. 5.%>
  6. 6.<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. 7.<html>
  8. 8.<head>
  9. 9.<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  10. 10.<script type="text/javascript" src="js/jquery.min.js"></script>
  11. 11.<script type="text/javascript" src="js/flexpaper.js"></script>
  12. 12.<script type="text/javascript" src="js/flexpaper_handlers.js"></script>
  13. 13.<style type="text/css" media="screen">
  14. 14. html, body { height:100%; }
  15. 15. body { margin:0; padding:0; overflow:auto; }
  16. 16. #flashContent { display:none; }
  17. 17. </style>
  18. 18.
  19. 19.<title>文檔在線預覽系統</title>
  20. 20.</head>
  21. 21.<body>
  22. 22. <div style="position:absolute;left:50px;top:10px;">
  23. 23. <div id="documentViewer" class="flexpaper_viewer" style="width:770px;height:500px"></div>
  24. 24.
  25. 25. <script type="text/javascript">
  26. 26.
  27. 27. var startDocument = "Paper";
  28. 28.
  29. 29. $('#documentViewer').FlexPaperViewer(
  30. 30. { config : {
  31. 31.
  32. 32. SWFFile : 'upload/ddd3.swf',
  33. 33.
  34. 34. Scale : 0.6,
  35. 35. ZoomTransition : 'easeOut',
  36. 36. ZoomTime : 0.5,
  37. 37. ZoomInterval : 0.2,
  38. 38. FitPageOnLoad : true,
  39. 39. FitWidthOnLoad : false,
  40. 40. FullScreenAsMaxWindow : false,
  41. 41. ProgressiveLoading : false,
  42. 42. MinZoomSize : 0.2,
  43. 43. MaxZoomSize : 5,
  44. 44. SearchMatchAll : false,
  45. 45. InitViewMode : 'Portrait',
  46. 46. RenderingOrder : 'flash',
  47. 47. StartAtPage : '',
  48. 48.
  49. 49. ViewModeToolsVisible : true,
  50. 50. ZoomToolsVisible : true,
  51. 51. NavToolsVisible : true,
  52. 52. CursorToolsVisible : true,
  53. 53. SearchToolsVisible : true,
  54. 54. WMode : 'window',
  55. 55. localeChain: 'en_US'
  56. 56. }}
  57. 57. );
  58. 58.
  59. 59. </script>
  60. 60. </div>
  61. 61.</body>
  62. 62.</html>

 

  1. <span style="font-family:Arial;font-size:12px;"><%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%
  4. //String swfFilePath=session.getAttribute("swfpath").toString();
  5. %>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. <html>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  10. <script type="text/javascript" src="js/jquery.min.js"></script>
  11. <script type="text/javascript" src="js/flexpaper.js"></script>
  12. <script type="text/javascript" src="js/flexpaper_handlers.js"></script>
  13. <style type="text/css" media="screen">
  14. html, body { height:100%; }
  15. body { margin:0; padding:0; overflow:auto; }
  16. #flashContent { display:none; }
  17. </style>
  18. <title>文檔在線預覽系統</title>
  19. </head>
  20. <body>
  21. <div style="position:absolute;left:50px;top:10px;">
  22. <div id="documentViewer" class="flexpaper_viewer" style="width:770px;height:500px"></div>
  23. <script type="text/javascript">
  24. var startDocument = "Paper";
  25. $('#documentViewer').FlexPaperViewer(
  26. { config : {
  27. SWFFile : 'upload/ddd3.swf',
  28. Scale : 0.6,
  29. ZoomTransition : 'easeOut',
  30. ZoomTime : 0.5,
  31. ZoomInterval : 0.2,
  32. FitPageOnLoad : true,
  33. FitWidthOnLoad : false,
  34. FullScreenAsMaxWindow : false,
  35. ProgressiveLoading : false,
  36. MinZoomSize : 0.2,
  37. MaxZoomSize : 5,
  38. SearchMatchAll : false,
  39. InitViewMode : 'Portrait',
  40. RenderingOrder : 'flash',
  41. StartAtPage : '',
  42. ViewModeToolsVisible : true,
  43. ZoomToolsVisible : true,
  44. NavToolsVisible : true,
  45. CursorToolsVisible : true,
  46. SearchToolsVisible : true,
  47. WMode : 'window',
  48. localeChain: 'en_US'
  49. }}
  50. );
  51. </script>
  52. </div>
  53. </body>
  54. </html></span>

        最後,若需要去除打印功能及logo,可重新編譯 flexpaper 的 flash文件,網上也有下載。

3、FlexPaper參數

Flexpaper可能用到如下參數



































SwfFile (String) 需要使用Flexpaper打開的文檔
Scale (Number) 初始化縮放比例,參數值應該是大於零的整數
ZoomTransition (String) Flexpaper中縮放樣式,它使用和Tweener一樣的樣式,默認參數值爲easeOut.其他可選值包括: easenone, easeout, linear, easeoutquad
ZoomTime (Number) 從一個縮放比例變爲另外一個縮放比例需要花費的時間,該參數值應該爲0或更大。
ZoomInterval (Number) 縮放比例之間間隔,默認值爲0.1,該值爲正數。
FitPageOnLoad (Boolean) 初始化得時候自適應頁面,與使用工具欄上的適應頁面按鈕同樣的效果。
FitWidthOnLoad (Boolean) 初始化的時候自適應頁面寬度,與工具欄上的適應寬度按鈕同樣的效果。
localeChain (String) 設置地區(語言),目前支持以下語言。

en_US (English) 
fr_FR (French) 
zh_CN (Chinese, Simple) 
es_ES (Spanish) 
pt_BR (Brazilian Portugese) 
ru_RU (Russian) 
fi_FN (Finnish) 
de_DE (German) 
nl_NL (Netherlands) 
tr_TR (Turkish) 
se_SE (Swedish) 
pt_PT (Portugese) 
el_EL (Greek) 
da_DN (Danish) 
cz_CS (Czech) 
it_IT (Italian) 
pl_PL (Polish) 
pv_FN (Finnish) 
hu_HU (Hungarian)

FullScreenAsMaxWindow (Boolean) 當設置爲true的時候,單擊全屏按鈕會打開一個flexpaper最大化的新窗口而不是全屏,當由於flash播放器因爲安全而禁止全屏,而使用flexpaper作爲獨立的flash播放器的時候設置爲true是個優先選擇。
ProgressiveLoading (Boolean) 當設置爲true的時候,展示文檔時不會加載完整個文檔,而是逐步加載,但是需要將文檔轉化爲9以上的flash版本(使用pdf2swf的時候使用-T 9 標籤)。
MaxZoomSize (Number) 設置最大的縮放比例。
MinZoomSize (Number) 最小的縮放比例。
SearchMatchAll (Boolean) 設置爲true的時候,單擊搜索所有符合條件的地方高亮顯示。
InitViewMode (String) 設置啓動模式如”Portrait” or “TwoPage”.
ViewModeToolsVisible (Boolean) 工具欄上是否顯示樣式選擇框。
ZoomToolsVisible (Boolean) 工具欄上是否顯示縮放工具。
NavToolsVisible (Boolean) 工具欄上是否顯示導航工具。
CursorToolsVisible (Boolean) 工具欄上是否顯示光標工具。

SearchToolsVisible (Boolean)

工具欄上是否顯示搜索。

 



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章