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

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

    • 分享

      java實(shí)現(xiàn)doc向swf格式的轉(zhuǎn)換 轉(zhuǎn)

       xihayouyi 2012-05-24
      java實(shí)現(xiàn)doc向swf格式的轉(zhuǎn)換 轉(zhuǎn)
      2012-02-03 14:46

       實(shí)現(xiàn)doc,ppt,txt等格式文件向可以在flexPaper中預(yù)覽的翻頁動(dòng)畫swf的格式轉(zhuǎn)換,一般需要先把doc,ppt,txt等格式的文件先轉(zhuǎn)換為pdf,然后再由pdf轉(zhuǎn)換為swf才能實(shí)現(xiàn)在flexpaper中進(jìn)行預(yù)覽,實(shí)現(xiàn)類似百度豆丁的預(yù)覽效果,其轉(zhuǎn)換過程需要電腦安裝 openoffice,swfTools軟件,通過java代碼:實(shí)現(xiàn)文檔格式的轉(zhuǎn)換,下面我將我在一個(gè)分布式項(xiàng)目中的一個(gè)文檔預(yù)覽部分的思路與大家共享:

      1.安裝openoffice,swfTools軟件,配置好java代碼的運(yùn)行環(huán)境。
      2.啟動(dòng)openOffice服務(wù):
          ①、進(jìn)入openoffice安裝目錄
               cd opeonofiice的安裝路徑/program
         ②、啟動(dòng)端口監(jiān)聽
                soffice -headless -accept="socket,host=127.0.0.1,port=8080;urp;" -nofirststartwizard
          ③、查看啟動(dòng)是否成功,存在8080端口即啟動(dòng)成功   netstat -an

      3.在eclipse端運(yùn)行以下java代碼,實(shí)現(xiàn)文檔的格式轉(zhuǎn)換,并保存到

       

         JodDemo.java:
         public class JodDemo {  
          public static int convertPDF2SWF(String sourcePath, String destPath, String fileName) throws IOException {  
              //目標(biāo)路徑不存在則建立目標(biāo)路徑  
              File dest = new File(destPath);  
              if (!dest.exists()) dest.mkdirs();  
                
              //源文件不存在則返回  
              File source = new File(sourcePath);  
              if (!source.exists()) return 0;  
                
              //調(diào)用pdf2swf命令進(jìn)行轉(zhuǎn)換  
              String command = "D:\\SWFTools\\pdf2swf.exe" + " -o \"" + destPath + "\\" + fileName + "\"  -s languagedir=D:\\xpdf\\xpdf-chinese-simplified -s flashversion=9 \"" + sourcePath + "\"";
                
              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();  
                
          }  
            
          public static void main(String []args) throws IOException {  
           String a = "世界各地國慶節(jié)";
              String sourcePath = "d:\\"+a+".pdf";  
              String destPath = "d:\\swf\\";  
              String fileName = a+".swf";  
              JodDemo.convertPDF2SWF(sourcePath, destPath, fileName);  
          }  
      }
      Office2Pdf.java
      public class Office2Pdf {

       public static void main(String[] args) throws Exception {
        String a = "世界各地國慶節(jié)";
        off2Pdf(a);
       }

       public static void off2Pdf(String fileName) {
        File inputFile = new File("d:/" + fileName + ".ppt");

        File outputFile = new File("d:/" + fileName + ".pdf");

        // connect to an OpenOffice.org instance running on port 8100

        OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);

        try {
         connection.connect();
        } catch (ConnectException e) {

         e.printStackTrace();
        }

        // convert

        DocumentConverter converter = new OpenOfficeDocumentConverter(
          connection);

        converter.convert(inputFile, outputFile);

        connection.disconnect();

       }

      }

      Pdf2Swf.java
      public class Pdf2Swf { 
          //實(shí)現(xiàn)由pdf格式到swf格式的轉(zhuǎn)換
          public int convertPDF2SWF(String sourcePath, String destPath,  
                  String fileName) throws IOException {  
              // 目標(biāo)路徑不存在則建立目標(biāo)路徑  
              File dest = new File(destPath);  
              if (!dest.exists()) {  
                  dest.mkdirs();  
              }  
       
              // 源文件不存在則返回  
              File source = new File(sourcePath);  
              if (!source.exists()) {  
                  return 0;  
              }  
         
              String[] envp = new String[1];  
              envp[0] = "PATH=D:\\SWFTools\\";  
              String command = "pdf2swf -z -s flashversion=9 \"" + sourcePath  
                      + "\" -o \"" + destPath + fileName + "\"";  
       
              Process pro = Runtime.getRuntime().exec(command, envp);  
              // System.out.println(command);  
              BufferedReader bufferedReader = new BufferedReader(  
                      new InputStreamReader(pro.getInputStream()));  
              while (bufferedReader.readLine() != null) {  
                  String text = bufferedReader.readLine();  
                  System.out.println(text);  
              }  
              try {  
                  pro.waitFor();  
              } catch (InterruptedException e) {  
                  // TODO Auto-generated catch block  
                  e.printStackTrace();  
              }  
              // 然后在套播放器  
                command = "swfcombine -z -X 720 -Y 540 \"D:/SWFTools/swfs/rfxview.swf\" viewport=\"" 
                      + destPath + fileName + "\" -o \"" + destPath + fileName + "\"";  
              pro = Runtime.getRuntime().exec(command, envp);  
              System.out.println(command);  
              bufferedReader = new BufferedReader(new InputStreamReader(pro  
                      .getInputStream()));  
              while (bufferedReader.readLine() != null) {  
                  String text = bufferedReader.readLine();  
                  System.out.println(text);  
              }  
              try {  
                  pro.waitFor();  
              } catch (InterruptedException e) {  
                  // TODO Auto-generated catch block  
                  e.printStackTrace();  
              }  
              return pro.exitValue();  
       
          }  
       
          public static void main(String[] args) {  
              String sourcePath = "d:/document.pdf";  
              String destPath = "d:/";  
              String fileName = "document.swf";  
              try {  
                  System.out.println(new Pdf2Swf().convertPDF2SWF(sourcePath,  
                          destPath, fileName));  
              } catch (IOException e) {  
                  // TODO Auto-generated catch block  
                  e.printStackTrace();  
              }  
          }  


       代碼已經(jīng)在MyEclipse上運(yùn)行測試無誤,可以實(shí)現(xiàn)將本地文件實(shí)現(xiàn)格式轉(zhuǎn)換,
      4.注意:注意代碼中加載各個(gè)軟件的本地路徑要正確,防止加載不到軟件而報(bào)錯(cuò)
               在代碼運(yùn)行前要啟動(dòng)openoffice服務(wù),否則不能完成文件格式的轉(zhuǎn)換  

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

        0條評(píng)論

        發(fā)表

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

        類似文章 更多