软件编程
位置:首页>> 软件编程>> java编程>> 基于Java SWFTools实现把pdf转成swf

基于Java SWFTools实现把pdf转成swf

作者:龙谷情Sinoam  发布时间:2023-09-01 20:19:02 

标签:SWFTools,pdf,swf

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

  • 1. 合并工具 swfcombine

  • 2. 抽取工具 swfextract

  • 3. PDF/JPEG/PNG/AVI/TTF/WAV 到 SWF 的转换工具 :pdf2swf, jpeg2swf, png2swf, avi2swf, font2swf, and wav2swf|

  • 4. 文本解析工具 swfstrings

  • 5. SWF 解析器 swfdump

  • 6. SWF 读写库 rfxswflib

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();
 }
...

来源:https://www.cnblogs.com/lgqrlchinese/p/13083608.html

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com