PDF 转 SWF

使用swftools软件工具,将pdf文档转换为swf文档,以便在FlexPaperViewer里使用




import java.io.IOException;
import java.io.InputStreamReader;

public class StringUtil {
	public static boolean executeCmdFlash(String cmd) {
		StringBuffer stdout=new StringBuffer();
		try {
			final Process process = Runtime.getRuntime().exec(cmd);
			Runtime.getRuntime().addShutdownHook(new Thread() {
				public void run() {
					process.destroy();
				}
			});
			InputStreamReader inputstreamreader = new InputStreamReader(process
					.getInputStream());
			char c = (char) inputstreamreader.read();
			if (c != '?')
				stdout.append(c);
			while (c != '?') {
				if (!inputstreamreader.ready()) {
					System.out.println(stdout);
					try {
						process.exitValue();
						break;
					} catch (IllegalThreadStateException _ex) {
						try {
							Thread.sleep(100L);
						} catch (InterruptedException _ex2) {
						}
					}
				} else {
					c = (char) inputstreamreader.read();
					stdout.append(c);
				}
			}
			try {
				inputstreamreader.close();
			} catch (IOException ioexception2) {
				System.err.println("RunCmd : Error closing InputStream "
						+ ioexception2);
				return false;
			}
		} catch (Throwable e) {
			e.printStackTrace();
		//	Globals.Logger("发生错误:" + e, 2);
			return false;
		}
		return true;
	}
	
	/**
	 * 取得文件名,去掉后缀
	 * @param file
	 * @return
	 */
	public static String getFileName(String file){
		if(file!=null && file.indexOf(".")!=-1){
			return file.substring(0,file.indexOf("."));
		}
		return "";
	}
	
	/**
	 * 转换pdf为swf
	 * @param softPath
	 * @param sourcePath
	 * @param destPath
	 * @param fileName 暂无实际作用,没有用到
	 * @return
	 */
	public static boolean pdf2swf(String softPath, String sourcePath, String destPath, String fileName){
		String cmd = softPath + sourcePath + " -o " + destPath + " -T 9";
		System.out.println("------开始pdf转换swf:" + sourcePath);
		if (StringUtil.executeCmdFlash(cmd) == false) {
			System.out.println("------转换pdf转换swf失败 error;cmd::::::" + cmd);
			return false;
		}else{
			System.out.println("success;cmd::::::" + cmd);
		}
		System.out.println("------结束pdf转换swf:" + sourcePath);
		return true;
	}
	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值