基于Java SWFTools实现把pdf转成swf
SWFTools是一组用来处理Flash的swf文件的工具包,包括:
- 1.合并工具swfcombine
- 2.抽取工具swfextract
- 3.PDF/JPEG/PNG/AVI/TTF/WAV到SWF的转换工具:pdf2swf,jpeg2swf,png2swf,avi2swf,font2swf,andwav2swf|
- 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
*
*/
privateFilepdf2swf(FilepdfFile)throwsException{
//下载的文件转成pdf的pdf将要放置的路径
StringswfPath=templateSwfDir+pdfFile.getName()+".swf";
FileswfFile=newFile(swfPath);
Runtimer=Runtime.getRuntime();
if(swfFile.exists()){
swfFile.delete();
}
if(!pdfFile.exists()){
thrownewException("程序出现问题,pdf不存在");
}
try{
Processp=r.exec(swfDir+""+pdfFile.getPath()+"-o"+swfFile.getPath()+"-T9");
loadStream(p.getInputStream());
loadStream(p.getErrorStream());
loadStream(p.getInputStream());
}catch(IOExceptione){
e.printStackTrace();
throwe;
}
returnswfFile;
}
staticStringloadStream(InputStreamin)throwsIOException{
intptr=0;
in=newBufferedInputStream(in);
StringBufferbuffer=newStringBuffer();
while((ptr=in.read())!=-1){
buffer.append((char)ptr);
}
returnbuffer.toString();
}
...
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。