pdf转swf

代码如下:


import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

public class Pdf2Swf {
    public static int convertPDF2SWF(String sourcePath, String destPath, String fileName) throws IOException {
    目标路径不存在则建立目标路径
            File dest = new File(destPath);
            if (!dest.exists()) dest.mkdirs();
            
            //源文件不存在则返回
            File source = new File(sourcePath);
            if (!source.exists()) return 0;
            
            //调用pdf2swf命令进行转换
//            String command = "D:\\swftools\\pdf2swf.exe" + " -o \"" + destPath  + fileName +"\"  <SPAN style='COLOR: #ff0000'>-s languagedir=D:\\xpdf\\xpdf-chinese-simplified</SPAN> -s flashversion=9 \"" + sourcePath + "\"";
//            String command = "D:\\swftools\\pdf2swf.exe" + " -o \"" + destPath  +  fileName +"\" -s flashversion=9 \"" + sourcePath + "\"";
            String command= "D:/Program Files/SWFTools/pdf2swf.exe  -t \""+destPath+"\\123.pdf\" -o  \""+destPath+"\\test.swf\" -s flashversion=9 -s languagedir=D:\\xpdf\\xpdf-chinese-simplified ";  
            System.out.println("cmd:"+command);
//            Process pro = Runtime.getRuntime().exec(command);
            Process process = Runtime.getRuntime().exec(command); // 调用外部程序   
            final InputStream is1 = process.getInputStream();   
            new Thread(new Runnable() {   
                public void run() {   
                    BufferedReader br = new BufferedReader(new InputStreamReader(is1));    
                    try {
                        while(br.readLine()!= null) ;
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }   
                }   
            }).start(); // 启动单独的线程来清空process.getInputStream()的缓冲区   
            InputStream is2 = process.getErrorStream();   
            BufferedReader br2 = new BufferedReader(new InputStreamReader(is2));    
            StringBuilder buf = new StringBuilder(); // 保存输出结果流   
            String line = null;   
            while((line = br2.readLine()) != null) buf.append(line); // 循环等待ffmpeg进程结束   
            System.out.println("输出结果为:" + buf);
            
// BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(pro.getInputStream()));
            while (br2.readLine() != null); 
            
            try {
                process.waitFor();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
            return process.exitValue();

            
        }

        
        public static void main(String []args) throws IOException {
            String sourcePath = "D:\\project\\rscms\\WebContent\\upload\\";
            String destPath = "D:\\project\\rscms\\WebContent\\upload\\";
            String fileName = "123.swf";
            try{
            	Pdf2Swf.convertPDF2SWF(sourcePath, destPath, fileName);
            
            }catch(Exception ex)
            {
                System.out.println("error");
            }
            System.out.println("success");
        
            
            
        }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

275261506

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值