PDF如何转为SWF

1,安装SWFTOOLS这个工具

直接下一步安装即可注意安装的目录路径不能有空格

2,编写java代码

package com.sunjingyi.test;

import java.io.BufferedReader;  
import java.io.File;  
import java.io.IOException;  
import java.io.InputStreamReader;  
/**
 * PDF转为SWF  
 * @author Sunny
 *
 */
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命令进行转换,这里写的是swftools的安装路径
        String command = "D:\\SWFTools\\SWFTools\\pdf2swf.exe" + " " + sourcePath+ " -o "   
                + destPath + fileName + " -f -T 9";  
        System.out.println(command);  
        Process pro = Runtime.getRuntime().exec(command);  
  
        BufferedReader bufferedReader = new BufferedReader(  
                new InputStreamReader(pro.getInputStream()));  
        while (bufferedReader.readLine() != null);  
        try {  
            pro.waitFor();  
        } catch (InterruptedException e) {  
            e.printStackTrace();  
        }  
        System.out.println(pro.exitValue());
        return pro.exitValue();  
    }  
  
    /** 
     * @param args 
     */  
    public static void main(String[] args) {  
        String sourcePath = "D:\\a.pdf"; //源文件路径  
        String destPath = "D:\\";        //目标路径  
        String fileName = "a.swf";       //生成文件名  
        try {  
        	PDF2SWF.convertPDF2SWF(sourcePath, destPath, fileName);  
        	System.out.println("转换成功!");
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  
}  

3,测试

1,首先在D盘要有a.pdf这个文件

2,如果成功之后,pro.exitValue();的值为0,其他值为失败

3,之后会在D盘根目录下生成a.swf即转换成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值