首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > PowerDesigner >

pdf转化成swf资料

2013-10-06 
pdf转化成swf文件一、需要用到pdf2swf.exe服务二、代码如下:package com.converterimport java.io.Buffered

pdf转化成swf文件
一、需要用到pdf2swf.exe服务
二、代码如下:

package com.converter;import java.io.BufferedReader;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.LineNumberReader;import java.util.Properties;public class PDF2SWF {public void converter(String name){// 服务器信息Properties props = System.getProperties();// 系统版本Linux,Window XP,Window 7String os_name = props.getProperty("os.name");String os_flag = "";if (os_name.indexOf("Linux") == 0) {os_flag = "linux";} else if (os_name.indexOf("Windows") == 0) {os_flag = "window";}//获得PDF文件File pdfFile = new File("D:/test/" + name);String fname = name.substring(0,name.lastIndexOf("."));//转换后存放的SWF文件File swfFile = new File("D:/test/" + fname  + ".swf");Runtime rt = Runtime.getRuntime();// 执行PDF文件转换成SWF文件命令// linux命令: pdf2swf// -slanguagedir=/usr/local/xpdf-chinese-simplified-T// 9 -s poly2bitmap -s zoom=150// -sflashversion=9"/home/s.pdf" -o "/home/%.swf"Process p = null;try {if (os_flag.equals("window")) {p = rt.exec("D:/swftool/" + "pdf2swf.exe  "+ pdfFile.getPath() + " -o "+ swfFile.getPath() + " -T 9 -G -s poly2bitmap");} else {p = rt.exec("pdf2swf -s languagedir=/usr/local/xpdf-chinese-simplified -T 9 -spoly2bitmap -s zoom=150 -s flashversion=9 "+ pdfFile.getPath()+ " -o "+ swfFile.getPath());}// 各系统清理缓存if (os_flag.equals("window")) {clearCache(p.getInputStream(), p.getErrorStream());} else if (os_flag.equals("linux")) {InputStreamReader ir = new InputStreamReader(p.getInputStream());LineNumberReader input = new LineNumberReader(ir);String line;while ((line = input.readLine()) != null) {}}} catch (IOException e) {e.printStackTrace();}} //清理缓冲区public void clearCache(InputStream isi, InputStream ise) {try {final InputStream is1 = isi;// 启用单独线程清空InputStream缓冲区new Thread(new Runnable() {public void run() {BufferedReader br = new BufferedReader(new InputStreamReader(is1));try {while (br.readLine() != null);} catch (IOException e) {e.printStackTrace();}}}).start();// 读入ErrorStream缓冲BufferedReader br = new BufferedReader(new InputStreamReader(ise));// 保存缓冲输出结果StringBuilder buf = new StringBuilder();String line = null;try {line = br.readLine();} catch (IOException e) {e.printStackTrace();}// 循环等待进程结束while (line != null)buf.append(line);is1.close();ise.close();br.close();} catch (Exception e) {e.printStackTrace();}}}

热点排行