PDF转换为SWF

发布时间:2020-08-01 18:28:04 作者:舜华
来源:网络 阅读:315
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

public class PdfConvertUtil {
	
	public static String convert(String filePath,String outPath){
		File file = new File(filePath);
		String  msg = "";
		String realName = outPath+"\\"+file.getName().substring(0,file.getName().length()-3)+"swf";
		if("pdf".equals(PdfConvertUtil.getPostfix(filePath))){
			try {
				StringBuffer cmd = new StringBuffer("D:\\swftools\\pdf2swf.exe ");
				cmd.append(" -o ");					//输出
				cmd.append(realName);
				cmd.append(" -t ");
				cmd.append(filePath);				//输入文件
				cmd.append(" -T -z -s languagedir=D:\\xpdf-chinese-simplified -s flashversion=9");//
				System.out.println(cmd.toString());
				Process p = Runtime.getRuntime().exec(cmd.toString());
				BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
				String line = "";
				while((line = reader.readLine()) != null){
					System.out.println(line);
					if(line.indexOf("Writing SWF file ") >= 0){
						msg = "PDF转换SWF成功!";
					}
				}
				if(p.waitFor() != 0){
					if(p.exitValue() == 1){
						msg = "PDF转换SWF失败!";
					}
				}
			} catch (IOException e) {
				e.printStackTrace();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}else{
			msg = "文件不是PDF格式!";
		}
		return msg;
	}
	
	
	
	public static String getPostfix(String filePath){
		File file = new File(filePath);
		if(file.isFile()){
			String fileName = file.getName();
			return fileName.substring(fileName.lastIndexOf('.')+1).toLowerCase();
		}
		return "";
	}
	
	public static void main(String[] args) {
		String filePath = "C:\\Users\\Administrator\\Downloads\\nodejs开发指南\\Node.js开发指南.pdf";
		System.out.println(PdfConvertUtil.convert(filePath,"C:\\Users\\Administrator\\Downloads\\nodejs开发指南"));
	}
}


推荐阅读:
  1. 实现word转pdf,HTML转pdf(探索篇)
  2. php将word转swf的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

pdf swf %d

上一篇:JavaWeb学习总结(一)___JavaWeb开发入门

下一篇:如何提高测试效率

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》