当前位置:主页 > 软件编程 > JAVA代码 >

基于Java SWFTools实现把pdf转成swf

时间:2021-05-08 09:08:14 | 栏目:JAVA代码 | 点击:

SWF Tools 是一组用来处理 Flash 的 swf 文件的工具包,包括:

1.下载swfTools并安装,下载地址http://www.swftools.org/download.html

2.复制代码到工具类中

...

  /**
   * pdf转swf
   * swfDir 存的exe文件路径,我的是:D:/SWFTools/pdf2swf.exe
   *
   */
  private File pdf2swf(File pdfFile) throws Exception {
    //下载的文件转成pdf的pdf将要放置的路径
    String swfPath = templateSwfDir + pdfFile.getName() + ".swf";
    File swfFile = new File(swfPath);
    Runtime r = Runtime.getRuntime();
    if (swfFile.exists()) {
      swfFile.delete();
    }
    if (!pdfFile.exists()) {
      throw new Exception("程序出现问题,pdf不存在");
    }
    try {
      Process p = r.exec(swfDir + " " + pdfFile.getPath() + " -o " + swfFile.getPath() + " -T 9");
      loadStream(p.getInputStream());
      loadStream(p.getErrorStream());
      loadStream(p.getInputStream());
    } catch (IOException e) {
      e.printStackTrace();
      throw e;
    }
    return swfFile;
  }
  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();
  }
...

您可能感兴趣的文章:

相关文章