flex实现百度库文浏览文档使用word文档转pdf然后再用pdf转swf最后flex页面使用flexpaper显示文库数据

6 篇文章 0 订阅

准备工作:

flex通过组建flexpaper显示百度文库效果需要在flex项目中添加jar包:

FlexPaper_Resources_SDK4.swc 和 FlexPaper_SDK4.swc 有了这两个jar包就能显示(右上角一直打圈圈显示不出来添加这两个包就好了)

下载路劲:http://code.google.com/p/flexpaper/downloads/list 下载sdk4.6的。

word等文档转pdf所用到的工具:1、Apache_OpenOffice_4.1.0_Win_x86_install_zh-CN.exe安装到本机上。下载路径:http://www.openoffice.org/

2、下载jar包:jodconverter-2.2.2.zip 把jar包拷贝到web工程。下载路劲:http://sourceforge.net/projects/jodconverter/files/JODConverter/

pdf转swf所用到的工具:pdf2swf 下载安装到本机上。

 

word转pdf代码:

 /**

     * 将Office文档转换为PDF. 运行该函数需要用到OpenOffice, OpenOffice下载地址为 
     * 
     * <pre>
     * 方法示例:
     * String sourcePath = "F:\\office\\source.doc";
     * String destFile = "F:\\pdf\\dest.pdf";
     * Converter.office2PDF(sourcePath, destFile);
     * </pre>
     * 
     * @param sourceFile
     *            源文件, 绝对路径. 可以是Office2003-2007全部格式的文档, Office2010的没测试. 包括.doc,
     *            .docx, .xls, .xlsx, .ppt, .pptx等. 示例: F:\\office\\source.doc
     * @param destFile
     *            目标文件. 绝对路径. 示例: F:\\pdf\\dest.pdf
     * @return 操作成功与否的提示信息. 如果返回 -1, 表示找不到源文件, 或url.properties配置错误; 如果返回 0,
     *         则表示操作成功; 返回1, 则表示转换失败
     */ 
    public static int office2PDF(String sourceFile, String destFile) { 
        try { 
            File inputFile = new File(sourceFile); 
            if (!inputFile.exists()) { 
                return -1;// 找不到源文件, 则返回-1 
            } 
 
            // 如果目标路径不存在, 则新建该路径 
            File outputFile = new File(destFile); 
            if (!outputFile.getParentFile().exists()) { 
                outputFile.getParentFile().mkdirs(); 
            } 
 
//            String OpenOffice_HOME = "C:\\Program Files\\OpenOffice 4";
//            String OpenOffice_HOME = "C:\\Program Files\\OpenOffice 4\\program\\soffice.exe";
//            office2pdfInstallPath
          //这里是OpenOffice的安装目录
            Properties pt = DocUtils.getInstallPath();
            String OpenOffice_HOME = pt.getProperty("office2pdfInstallPath");
                  // 启动OpenOffice的服务   
//            String command = OpenOffice_HOME 
//                    + "program\\soffice.exe -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\""; 
            String command = OpenOffice_HOME 
            + " -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\""; 
            Process pro = Runtime.getRuntime().exec(command); 
            // connect to an OpenOffice.org instance running on port 8100 
            OpenOfficeConnection connection = new SocketOpenOfficeConnection( 
                    "127.0.0.1", 8100); 
            connection.connect(); 
 
            // convert 
            DocumentConverter converter = new OpenOfficeDocumentConverter( 
                    connection); 
            converter.convert(inputFile, outputFile); 
 
            // close the connection 
            connection.disconnect(); 
            // 关闭OpenOffice服务的进程 
            pro.destroy(); 
 
            return 0; 
        } catch (FileNotFoundException e) { 
            e.printStackTrace(); 
            return -1; 
        } catch (ConnectException e) { 
            e.printStackTrace(); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
        return 1; 
    }

 

pdf 转swf代码:

/**
  * PDF转SWF工具
   * @param PDF2SWFInstallPath 安装路径
  * @param sourcePath PDF存放路径
  * @param destPath SWF存放路径
  * @return 0 表示成功
  * @throws IOException
  */
 public static int convertPDF2SWF(String pdf2SWFInstallPath,String sourcePath, String destPath) throws IOException {
   /*//目标路径不存在则建立目标路径
   File dest = new File(destPath);
   if (!dest.exists()) dest.mkdirs();*/
   
   //源文件不存在则返回
   File source = new File(sourcePath);
   if (!source.exists()) return -1;
   
   //调用pdf2swf命令进行转换
   // E:/Program Files/SWFTools/pdf2swf.exe  -t "D:\swf\oa详细设计.pdf" -o  "D:\swf\test.swf" -s flashversion=9
   // E:/Program Files/SWFTools/pdf2swf.exe  -t "D:\swf\oa详细设计.pdf" -o  "D:\swf\test.swf" -s flashversion=9
//   String command= "E:/Program Files/SWFTools/pdf2swf.exe  -t \""+sourcePath+"\\oa详细设计.pdf\" -o  \""+sourcePath+"\\test.swf\" -s flashversion=9 ";
//   String command= "E:/Program Files/SWFTools/pdf2swf.exe  -t \""+sourcePath+"\""+" -o  "+ "\""+destPath+"\""+" -s flashversion=9 ";
   String command= pdf2SWFInstallPath+"  -t \""+sourcePath+"\""+" -o  "+ "\""+destPath+"\""+" -s flashversion=9 ";
//   E:\Program Files\SWFTools\
   
//   String command= "E:/Program Files/SWFTools/pdf2swf.exe  -t \""+sourcePath+"\\test.pdf\" -o  \""+sourcePath+"\\test.swf\" -s flashversion=9 ";
   System.out.println(command);
//   "E:\Program Files\SWFTools\gpdf2swf.exe"
   
   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(); // 返回 0 表示转换成功
  }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值