乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      網(wǎng)頁(yè)文檔在線瀏覽(仿百度文庫(kù)設(shè)計(jì))

       corefashion 2014-08-08

      openoffice.org3+swftools+flexpaper(一)之tomcat6.0+jdk1.6環(huán)境配置

              仿百度文庫(kù)設(shè)計(jì),是筆者很早就想模仿實(shí)現(xiàn)的,剛好有一個(gè)項(xiàng)目,催促我學(xué)習(xí)開(kāi)發(fā)。其實(shí)網(wǎng)上關(guān)類似的文章很多,但筆者想根據(jù)自己的開(kāi)發(fā)經(jīng)驗(yàn),總結(jié)這次的成果。

             首先,筆者的開(kāi)發(fā)環(huán)境是Myeclipse+tomcat6.0+jdk1.6

             其次,為了使doc、pdf等格式的文檔能夠在線瀏覽,需要一個(gè)插件,即felxpaper。它是一款flash的播放軟件,即支持swf文件的在線播放。所以,我們需要把doc、pdf等文件轉(zhuǎn)換為flash文件,然后再用flexpap在線瀏覽。openoffice的功能很強(qiáng)大,可以把doc文件轉(zhuǎn)換為pdf、swf等格式。swftools可以把pdf文件轉(zhuǎn)換為swf文件。

             最后,通過(guò)耐心的編寫(xiě)代碼,即可。

             關(guān)于tomcat、jdk的配置,筆者不想過(guò)多闡述,這是每個(gè)開(kāi)發(fā)人員具備的基礎(chǔ)。

      openoffice.org3+swftools+flexpaper(二)之openoffice.org的安裝

      安裝openoffice.org

           openoffice.org是一套sun的開(kāi)源office辦公套件,能在widows,linux,solaris等操作系統(tǒng)上執(zhí)行。

      主要模塊有writer(文本文檔),impress(演示文稿),Calc(電子表格),Draw(繪圖),Math(公式),base(數(shù)據(jù)庫(kù))

      筆者下載的是OpenOffice.org 3.4.0 Final.exe。下載完直接安裝即可。

       

           但是,我們還需要啟動(dòng)openoffice server。有兩種做法:

          1.以命令行方式啟動(dòng)openoffice server,缺點(diǎn)是每次系統(tǒng)重啟,都需要手動(dòng)去把openoffice server啟動(dòng)。

          2.將openoffice server作為操作系統(tǒng)的服務(wù)啟動(dòng),既然成為了系統(tǒng)服務(wù),就可以設(shè)定開(kāi)機(jī)自動(dòng)啟動(dòng)了。

          我們先來(lái)看第一種方式,

      1.以命令行方式啟動(dòng)openoffice server

        在cmd命令下,cd opeonofiice的安裝路徑/program 如:cd c:\program files\openoffice.org 3\program

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

       

      2.以系統(tǒng)服務(wù)的方式啟動(dòng)

          這里我們還需要Windows Resource Kit tools ,將openoffice server設(shè)為系統(tǒng)服務(wù)。

      Windows Resource Kit tools 是微軟專為管理人員、開(kāi)發(fā)人員和高級(jí)用戶開(kāi)發(fā)的,包括管理活動(dòng)目錄、組策略、TCP/IP網(wǎng)絡(luò)、注冊(cè)表、系統(tǒng)安全、監(jiān)測(cè)等涉及Windows Server 2003 操作系統(tǒng)的其它很多方面的非常規(guī)安裝的工具組件。Resource Kit Tools for XP的發(fā)布使得XP用戶也能使用Resource Kit Tools對(duì)這些問(wèn)題進(jìn)行處理。

          下載windows resource kit tools,我們進(jìn)行默認(rèn)安裝。

           1.打開(kāi)Windows Resource Kit Tools

           在Command Shell執(zhí)行以下命令:

       "C:\Program Files\Windows Resource Kits\Tools\instsrv" OpenOfficeUnoServer "C:\Program Files\Windows Resource Kits\Tools\srvany.exe"

      打開(kāi) 管理工具->服務(wù) 可以找到以 OpenOfficeUnoServer 命名的服務(wù)

          2.打開(kāi)注冊(cè)表尋找以下路徑

          HKEY_LOCAL_MACHINE -> SYSTEM ->ControlSet001 ->Services ->OpenOfficeUnoServer

        新建項(xiàng) Parameters,在該項(xiàng)下添加兩個(gè)字符串值:

        key:Application

           value:C:\Program Files\OpenOffice.org 3\program\soffice.exe

       

           key:AppParameters

           value:-invisible -headless -accept=socket,host=127.0.0.1,port=8100;urp; -nofirststartwizard

       

           3.在服務(wù)控制臺(tái),啟動(dòng) openoffice 服務(wù)

           4.在CMD中用以下命令查看8100是否已被監(jiān)聽(tīng):netstat -anop tcp

      這樣OpenOffice3.0就以服務(wù)方式運(yùn)行在Windows系統(tǒng)上了。(使用cmd命令:netstat -anp tcp查看8100端口是否工作)

      然後可以通過(guò)socket方式連接openOffice,以使用openoffice提供的某些服務(wù),如文件轉(zhuǎn)換服務(wù),ms office轉(zhuǎn)pdf等等。

      開(kāi)源項(xiàng)目 JODConverter 就是結(jié)合openoffice來(lái)進(jìn)行文檔轉(zhuǎn)換的java組件。

      另外有一個(gè)命令行工具swftools,該工具可以將pdf轉(zhuǎn)換為swf格式的文檔,提供給ie客戶端流覽。    

        另外,我們可以將該配置用bat文件來(lái)快速實(shí)現(xiàn),運(yùn)行前請(qǐng)先修改相應(yīng)目錄參數(shù):

           openoffice service.bat文件

          "C:\Program Files\Windows Resource Kits\Tools\instsrv" OpenOfficeUnoServer "C:\Program Files\Windows Resource Kits\Tools\srvany.exe"
          reg add HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\OpenOfficeUnoServer\Parameters /ve /d
          reg add HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\OpenOfficeUnoServer\Parameters /v Application /t REG_SZ /d "C:\Program Files\OpenOffice.org 3\program\soffice.exe"
          reg add HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\OpenOfficeUnoServer\Parameters /v AppParameters /t REG_SZ /d "-invisible -headless -accept=socket,host=127.0.0.1,port=8100;urp; -nofirststartwizard"

       

       

      openoffice.org3+swftools+flexpaper(三)之使用JODConverter將office文檔轉(zhuǎn)換為pdf

      JODConverter是一個(gè)java的OpenDucument文件轉(zhuǎn)換器,可以進(jìn)行許多文件格式的轉(zhuǎn)換,它利用

      OpenOffice來(lái)進(jìn)行轉(zhuǎn)換工作,它能進(jìn)行以下的轉(zhuǎn)換工作:

           1.Microsoft Office格式轉(zhuǎn)換為OpenDucument,以及OpenDucument轉(zhuǎn)換為Microsoft Office

           2.OpenDucument轉(zhuǎn)換為PDF,Word、Excel、PowerPoint轉(zhuǎn)換為PDF,RTF轉(zhuǎn)換為PDF等。

      它是一個(gè)開(kāi)源項(xiàng)目。

       

      下載最新版的jodconverter-2.2.2,把lib文件夾的包導(dǎo)入到你的DocConverter項(xiàng)目的lib文件夾內(nèi)。

      (假設(shè)你的項(xiàng)目是DocConverter)

      新建DOC2PDFUtil.java

      代碼:

      package com.iori.webapp.util;
      import java.io.File;
      import java.io.IOException;
      import java.net.ConnectException;
      import java.util.Date;

      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;

      public class DOC2PDFUtil extends java.lang.Thread {
      private File inputFile;// 需要轉(zhuǎn)換的文件

      private File outputFile;// 輸出的文件

      public DOC2PDFUtil(File inputFile, File outputFile) {
      this.inputFile = inputFile;
      this.outputFile = outputFile;
      }

      public void docToPdf() {
      Date start = new Date();

      OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
      try {
      connection.connect();
      DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
      converter.convert(inputFile, outputFile);
      } catch (ConnectException cex) {
      cex.printStackTrace();
      } finally {
      // close the connection

      if (connection != null) {
      connection.disconnect();
      connection = null;
      }
      }
      }

      /**

      * 由于服務(wù)是線程不安全的,所以……需要啟動(dòng)線程
      */
      public void run() {
      this.docToPdf();
      }

      public File getInputFile() {
      return inputFile;
      }

      public void setInputFile(File inputFile) {
      this.inputFile = inputFile;
      }

      public File getOutputFile() {
      return outputFile;
      }

      public void setOutputFile(File outputFile) {
      this.outputFile = outputFile;
      }

      /**

      * 測(cè)試main方法
      *
      @param args
      */
      public static void main(String[] args) {
      File inputFile = new File("c://temp//333.xls");
      File outputFile = new File("c://temp//333.pdf");
      DOC2PDFUtil dp=new DOC2PDFUtil(inputFile,outputFile);
      dp.start();
      }
      }

      在DOC2PDFUtil.java,右鍵屬性 - >Run as - >Java Application ,輸出main的測(cè)試結(jié)果。

      在jsp中執(zhí)行

      新建MyDOC2PDFTest.jsp

      <%@ page import="java.io.*"%>
      <%@ page import="com.artofsolving.jodconverter.openoffice.connection.*"%>
      <%@ page import="com.artofsolving.jodconverter.openoffice.connection.*"%>
      <%@ page import="com.artofsolving.jodconverter.openoffice.converter.*"%>
      <%@ page import="com.artofsolving.jodconverter.*"%>
      <%@ page import="java.util.*"%>
      <%@ page import="com.iori.webapp.util.*"%>

      <%
      File inputFile = new File("c://temp//333.xls");
      File outputFile = new File("c://temp//333.pdf");
      DOC2PDFUtil dp=new DOC2PDFUtil(inputFile,outputFile);
      dp.start();
      %>

      <!-- 下面這些html可以去掉 -->

      <html>
      <head><title>Simple jsp page</title></head>
      <body>Place your content here</body>
      </html>

      在項(xiàng)目DocConverter根目錄,右鍵屬性 - >Run as - >MyEclipse Server Application

      發(fā)布到之前安裝的Tomcat 6.0的根目錄,然后用url路徑訪問(wèn):Http://localhost:8080/DocConverter/MyDOC2PDFTest.jsp 進(jìn)行測(cè)試。

      JODConverter將office文檔轉(zhuǎn)換pdf,用到的代碼如下:

       

      File inputFile = new File("c://temp//333.xls");
      File outputFile = new File("c://temp//333.pdf");

      // 鏈接 一個(gè)運(yùn)行在8100端口的OpenOffice.org 實(shí)例
      OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
      connection.connect();

      // 創(chuàng)建一個(gè)converter對(duì)象并轉(zhuǎn)換格式
      DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
      converter.convert(inputFile, outputFile);

      // 關(guān)閉連接
      connection.disconnect();


      openoffice.org3+swftools+flexpaper(四)之使用swftools將pdf轉(zhuǎn)換為swf

      建議下載swftools-0.9.1,筆者起先下載的是最新版的swftools-1.0版。貌似轉(zhuǎn)換時(shí)出錯(cuò),缺少什么組件。

       

      注意:使用此軟件會(huì)出現(xiàn)轉(zhuǎn)換中文文檔時(shí)亂碼。

      下面是一些常用的解決辦法:

      1.txt轉(zhuǎn)換swf,發(fā)生中文亂碼。

      txt轉(zhuǎn)換為utf-8編碼,或txt格式手動(dòng)改為odt,上傳就不會(huì)發(fā)生亂碼。從根源上解決,暫時(shí)就算了...暫時(shí)不想去糾結(jié)這些雞毛。

      2.加密的pdf可能導(dǎo)致轉(zhuǎn)換為swf失敗。

      3.Microsoft Excel在公式運(yùn)算中支持文本型的數(shù)值,而OpenOffice.org Calc不支持

      此問(wèn)題暫無(wú)解,請(qǐng)手動(dòng)將Excel中文本型的數(shù)值修改為數(shù)值型的數(shù)值。

      4.部分Excel存在過(guò)于豐富的樣式(大部分指沒(méi)有數(shù)據(jù)的單元格也填充了各種樣式),即使用專業(yè)Adobe Acrobat 7(或9) Pro來(lái)進(jìn)行轉(zhuǎn)換,

      本來(lái)可能預(yù)計(jì)將產(chǎn)生20-30分頁(yè)的pdf,結(jié)果卻產(chǎn)生800-900分頁(yè)的pdf。此類文檔在線轉(zhuǎn)換,難以避免的將導(dǎo)致轉(zhuǎn)換死鎖。

      請(qǐng)?jiān)谀愕腅xcel文檔中刪除多余的,毫無(wú)必要的樣式,或者你有更靈活的做法。

      5.有些中文PDF文件轉(zhuǎn)換為SWF后,出現(xiàn)亂碼(特別一些專業(yè)期刊)

       1.下載XPDF:xpdf-chinese-simplified.tar.gz

       2.下載字體:gkai00mp.rar

       3.修改xpdf-chinese-simplified目錄下的add-to-xpdfrc文件。將里面的路徑設(shè)為自己的路徑:

      #----- begin Chinese Simplified support package (2011-sep-02)
      cidToUnicode Adobe-GB1    C:\xpdf-chinese-simplified\Adobe-GB1.cidToUnicode
      unicodeMap   ISO-2022-CN C:\xpdf-chinese-simplified\ISO-2022-CN.unicodeMap
      unicodeMap   EUC-CN         C:\xpdf-chinese-simplified\EUC-CN.unicodeMap
      unicodeMap   GBK              C:\xpdf-chinese-simplified\GBK.unicodeMap
      cMapDir        Adobe-GB1    C:\xpdf-chinese-simplified\CMap
      toUnicodeDir                     C:\xpdf-chinese-simplified\CMap
      fontDir                             C:\WINDOWS\Fonts
      displayCIDFontTT Adobe-GB1 C:\xpdf-chinese-simplified\CMap\gkai00mp.ttf
      #fontFileCC Adobe-GB1 /usr/..../gkai00mp.ttf
      #----- end Chinese Simplified support package

       4.參照上面的代碼,在調(diào)用pdf2swf命令中加入“ -s languagedir=D:\\xpdf\\xpdf-chinese-simplified ”參數(shù)。

      PDF2SWFUtil.java

      String cmd = exePath + " \"" + fileDir + "\" -o \"" + filePath + "/" + fileName + ".swf\" -T 9 -s languagedir=c:\\xpdf-chinese-simplified";

      這樣亂碼的問(wèn)題就解決了。

           繼續(xù)筆者的DocConverter項(xiàng)目。筆者使用的開(kāi)發(fā)環(huán)境是MyEclipse 9.0。

      新建PDF2SWFUtil.java

      package com.iori.webapp.util;
      import java.io.BufferedReader;
      import java.io.IOException;
      import java.io.InputStream;
      import java.io.InputStreamReader;

      public class PDF2SWFUtil {

      /**

      * 利用SWFTools工具將pdf轉(zhuǎn)換成swf,轉(zhuǎn)換完后的swf文件與pdf同名
      *
      @author iori
      *
      @param
      fileDir PDF文件存放路徑(包括文件名)
      *
      @param
      exePath 轉(zhuǎn)換器安裝路徑
      *
      @throws
      IOException
      */
      public static synchronized void pdf2swf(String fileDir, String exePath) throws IOException {
      //文件路徑

      String filePath = fileDir.substring(0, fileDir.lastIndexOf("/"));
      //文件名,不帶后綴

      String fileName = fileDir.substring((filePath.length() + 1), fileDir.lastIndexOf("."));
      Process pro = null;
      if (isWindowsSystem()) {
      //
      如果是windows系統(tǒng)
      //命令行命令

      String cmd = exePath + " \"" + fileDir + "\" -o \"" + filePath + "/" + fileName + ".swf\"";
      //Runtime執(zhí)行后返回創(chuàng)建的進(jìn)程對(duì)象

      pro = Runtime.getRuntime().exec(cmd);
      } else {
      //如果是linux系統(tǒng),路徑不能有空格,而且一定不能用雙引號(hào),否則無(wú)法創(chuàng)建進(jìn)程

      String[] cmd = new String[3];
      cmd[0] = exePath;
      cmd[1] = fileDir;
      cmd[2] = filePath + "/" + fileName + ".swf";
      //Runtime執(zhí)行后返回創(chuàng)建的進(jìn)程對(duì)象

      pro = Runtime.getRuntime().exec(cmd);
      }
      //非要讀取一遍cmd的輸出,要不不會(huì)flush生成文件(多線程)

      new DoOutput(pro.getInputStream()).start();
      new DoOutput(pro.getErrorStream()).start();
      try {
      //調(diào)用waitFor方法,是為了阻塞當(dāng)前進(jìn)程,直到cmd執(zhí)行完

      pro.waitFor();
      } catch (InterruptedException e) {
      e.printStackTrace();
      }
      }

      /**

      * 判斷是否是windows操作系統(tǒng)
      *
      @author iori
      *
      @return

      */
      private static boolean isWindowsSystem() {
      String p = System.getProperty("os.name");
      return p.toLowerCase().indexOf("windows") >= 0 ? true : false;
      }

      /**

      * 多線程內(nèi)部類
      * 讀取轉(zhuǎn)換時(shí)cmd進(jìn)程的標(biāo)準(zhǔn)輸出流和錯(cuò)誤輸出流,這樣做是因?yàn)槿绻蛔x取流,進(jìn)程將死鎖
      *
      @author iori
      */
      private static class DoOutput extends Thread {
      public InputStream is;

      //構(gòu)造方法

      public DoOutput(InputStream is) {
      this.is = is;
      }

      public void run() {
      BufferedReader br = new BufferedReader(new InputStreamReader(this.is));
      String str = null;
      try {
      //這里并沒(méi)有對(duì)流的內(nèi)容進(jìn)行處理,只是讀了一遍

      while ((str = br.readLine()) != null);
      } catch (IOException e) {
      e.printStackTrace();
      } finally {
      if (br != null) {
      try {
      br.close();
      } catch (IOException e) {
      e.printStackTrace();
      }
      }
      }
      }
      }

      /**

      * 測(cè)試main方法
      *
      @param args
      */
      public static void main(String[] args) {
      //轉(zhuǎn)換器安裝路徑

      String exePath = "c:/Program Files/SWFTools/pdf2swf.exe";
      try {
      PDF2SWFUtil.pdf2swf("c:/temp/333.pdf", exePath);
      } catch (IOException e) {
      System.err.println("轉(zhuǎn)換出錯(cuò)!");
      e.printStackTrace();
      }
      }
      }

      在PDF2SWFUtil.java,右鍵屬性 - >Run as - >Java Application ,輸出main的測(cè)試結(jié)果。

       

      在jsp中執(zhí)行

      新建MyPDF2SWFTest.jsp

       

      <%@ page import="java.io.*"%>
      <%@ page import="com.artofsolving.jodconverter.openoffice.connection.*"%>
      <%@ page import="com.artofsolving.jodconverter.openoffice.connection.*"%>
      <%@ page import="com.artofsolving.jodconverter.openoffice.converter.*"%>
      <%@ page import="com.artofsolving.jodconverter.*"%>
      <%@ page import="java.util.*"%>
      <%@ page import="com.iori.webapp.util.*"%>

      <%
      //轉(zhuǎn)換器安裝路徑

      String exePath = "c:/Program Files/SWFTools/pdf2swf.exe";
      try {
      PDF2SWFUtil.pdf2swf("c:/temp/333.pdf", exePath);
      } catch (IOException e) {
      System.err.println("轉(zhuǎn)換出錯(cuò)!");
      e.printStackTrace();
      }
      %>

      <!-- 下面這些html可以去掉 -->
      <html>
      <head>
      <title>Simple jsp page</title>
      </head>
      <body>Place your content here</body>
      </html>


       

      在項(xiàng)目DocConverter根目錄,右鍵屬性 - >Run as - >MyEclipse Server Application

      發(fā)布到之前安裝的Tomcat 6.0的根目錄,然后用url路徑訪問(wèn):Http://localhost:8080/DocConverter/MyPDF2SWFTest.jsp 進(jìn)行測(cè)試。
      openoffice.org3+swftools+flexpaper(五)之轉(zhuǎn)換pdf的同時(shí),進(jìn)一步轉(zhuǎn)換為swf

      新建DocConverter.java

       

      package com.iori.webapp.util;
      import java.io.BufferedInputStream;
      import java.io.File;
      import java.io.IOException;
      import java.io.InputStream;
      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;

      /*

      * doc docx格式轉(zhuǎn)換
      * @author Administrator
      */
      public class DocConverter {
      private static final int environment=1;//環(huán)境1:windows 2:linux(涉及pdf2swf路徑問(wèn)題)

      private String fileString;
      private String outputPath="";//輸入路徑,如果不設(shè)置就輸出在默認(rèn)位置

      private String fileName;
      private File pdfFile;
      private File swfFile;
      private File docFile;

      public DocConverter(String fileString)
      {
      ini(fileString);
      }

      /*

      * 重新設(shè)置 file
      * @param fileString
      */
      public void setFile(String fileString)
      {
      ini(fileString);
      }

      /*

      * 初始化
      * @param fileString
      */
      private void ini(String fileString)
      {
      this.fileString=fileString;
      fileName=fileString.substring(0,fileString.lastIndexOf("."));
      docFile=new File(fileString);
      pdfFile=new File(fileName+".pdf");
      swfFile=new File(fileName+".swf");
      }

      /*

      * 轉(zhuǎn)為PDF
      * @param file
      */
      private void doc2pdf() throws Exception
      {
      if(docFile.exists())
      {
      if(!pdfFile.exists())
      {
      OpenOfficeConnection connection=new SocketOpenOfficeConnection(8100);
      try
      {
      connection.connect();
      DocumentConverter converter=new OpenOfficeDocumentConverter(connection);
      converter.convert(docFile,pdfFile);
      //close the connection

      connection.disconnect();
      System.out.println("****pdf轉(zhuǎn)換成功,PDF輸出:"+pdfFile.getPath()+"****");
      }
      catch(java.net.ConnectException e)
      {
      //ToDo Auto-generated catch block

      e.printStackTrace();
      System.out.println("****swf轉(zhuǎn)換異常,openoffice服務(wù)未啟動(dòng)!****");
      throw e;
      }
      catch(com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e)
      {
      e.printStackTrace();
      System.out.println("****swf轉(zhuǎn)換器異常,讀取轉(zhuǎn)換文件失敗****");
      throw e;
      }
      catch(Exception e)
      {
      e.printStackTrace();
      throw e;
      }
      }
      else
      {
      System.out.println("****已經(jīng)轉(zhuǎn)換為pdf,不需要再進(jìn)行轉(zhuǎn)化****");
      }
      }
      else
      {
      System.out.println("****swf轉(zhuǎn)換器異常,需要轉(zhuǎn)換的文檔不存在,無(wú)法轉(zhuǎn)換****");
      }
      }

      /*

      * 轉(zhuǎn)換成swf
      */
      private void pdf2swf() throws Exception
      {
      Runtime r=Runtime.getRuntime();
      if(!swfFile.exists())
      {
      if(pdfFile.exists())
      {
      if(environment==1)//windows環(huán)境處理

      {
      try {
      Process p=r.exec("C:/Program Files/SWFTools/pdf2swf.exe "+pdfFile.getPath()+" -o "+swfFile.getPath()+" -T 9");
      System.out.print(loadStream(p.getInputStream()));
      System.err.print(loadStream(p.getErrorStream()));
      System.out.print(loadStream(p.getInputStream()));
      System.err.println("****swf轉(zhuǎn)換成功,文件輸出:"+swfFile.getPath()+"****");
      if(pdfFile.exists())
      {
      pdfFile.delete();
      }
      } catch (Exception e) {
      e.printStackTrace();
      throw e;
      }
      }
      else if(environment==2)//linux環(huán)境處理

      {
      try {
      Process p=r.exec("pdf2swf "+pdfFile.getPath()+" -o "+swfFile.getPath()+" -T 9");
      System.out.print(loadStream(p.getInputStream()));
      System.err.print(loadStream(p.getErrorStream()));
      System.err.println("****swf轉(zhuǎn)換成功,文件輸出:"+swfFile.getPath()+"****");
      if(pdfFile.exists())
      {
      pdfFile.delete();
      }
      } catch (Exception e) {
      e.printStackTrace();
      throw e;
      }
      }
      }
      else {
      System.out.println("****pdf不存在,無(wú)法轉(zhuǎn)換****");
      }
      }
      else {
      System.out.println("****swf已存在不需要轉(zhuǎn)換****");
      }
      }

      static String loadStream(InputStream in) throws IOException
      {
      int ptr=0;
      in=new BufferedInputStream(in);
      StringBuffer buffer=new StringBuffer();

      while((ptr=in.read())!=-1)
      {
      buffer.append((char)ptr);
      }
      return buffer.toString();
      }

      /*

      * 轉(zhuǎn)換主方法
      */
      public boolean conver()
      {
      if(swfFile.exists())
      {
      System.out.println("****swf轉(zhuǎn)換器開(kāi)始工作,該文件已經(jīng)轉(zhuǎn)換為swf****");
      return true;
      }

      if(environment==1)
      {
      System.out.println("****swf轉(zhuǎn)換器開(kāi)始工作,當(dāng)前設(shè)置運(yùn)行環(huán)境windows****");
      }
      else {
      System.out.println("****swf轉(zhuǎn)換器開(kāi)始工作,當(dāng)前設(shè)置運(yùn)行環(huán)境linux****");
      }

      try {
      doc2pdf();
      pdf2swf();
      } catch (Exception e) {
      // TODO: Auto-generated catch block

      e.printStackTrace();
      return false;
      }

      if(swfFile.exists())
      {
      return true;
      }
      else {
      return false;
      }
      }

      /*

      * 返回文件路徑
      * @param s
      */
      public String getswfPath()
      {
      if(swfFile.exists())
      {
      String tempString =swfFile.getPath();
      tempString=tempString.replaceAll("\\\\", "/");
      return tempString;
      }
      else{
      return "";
      }
      }

      /*

      * 設(shè)置輸出路徑
      */
      public void setOutputPath(String outputPath)
      {
      this.outputPath=outputPath;
      if(!outputPath.equals(""))
      {
      String realName=fileName.substring(fileName.lastIndexOf("/"),fileName.lastIndexOf("."));
      if(outputPath.charAt(outputPath.length())=='/')
      {
      swfFile=new File(outputPath+realName+".swf");
      }
      else
      {
      swfFile=new File(outputPath+realName+".swf");
      }
      }
      }

      public static void main(String s[])
      {
      DocConverter d=new DocConverter("c:/temp/111.ppt");
      d.conver();
      }
      }
      在DocConverter.java,右鍵屬性 - >Run as - >Java Application ,輸出main的測(cè)試結(jié)果。筆者分別進(jìn)行單個(gè)轉(zhuǎn)換,及批量轉(zhuǎn)換,都測(cè)試可行。
      openoffice.org3+swftools+flexpaper(六)之flexpaper在線瀏覽swf文檔

      FlexPaper是一個(gè)開(kāi)源輕量級(jí)的在瀏覽器上顯示各種文檔的組件,被設(shè)計(jì)用來(lái)與PDF2SWF一起使用,

      使在Flex中顯示PDF成為可能,而這個(gè)過(guò)程并無(wú)需PDF軟件環(huán)境的支持。它可以被當(dāng)做Flex的庫(kù)來(lái)使用。

      另外你也可以通過(guò)將一些例如Word、PPT等文檔轉(zhuǎn)成PDF,然后實(shí)現(xiàn)在線瀏覽。

      下載FlexPaper_1.2.4_flash(1).zip即可

      解壓后,文件如圖:

      網(wǎng)頁(yè)文檔在線瀏覽(仿百度文庫(kù)設(shè)計(jì)) - 線上的思考者 - 線上的思考者

       

      FlexPaper項(xiàng)目中有演示demo,即打開(kāi)FlexPaperViewer.html便可在線瀏覽文檔Paper.swf,這里筆者不多述。

      綜上,一個(gè)完整的在線文檔瀏覽方案。
      但是需要注意一個(gè)問(wèn)題,flexpaper不支持中文路徑,若想使用中文路徑,需要進(jìn)行felxpaper的二次開(kāi)發(fā),有點(diǎn)麻煩。需要下載adobe flash bulider軟件以及flexPaper源代碼。讀者可下載flexpaper二次開(kāi)發(fā)教程,進(jìn)行相應(yīng)的修改。

       

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多