将PDF转换为SWF文件和截取视频(格式这FLV)图片

最近在做一个企业的网站

1:需要实现杂志功能,杂志是上传的PDF文件,上传后可以在页面中显示查看浏览.

网上有一个成熟的解决方案是swftool,将PDF转换为SWF文件(它还在其它格式的文件转换为SWF文件的,详见官方说明),adobe的FLASH大部分浏览器都支持

所以在客户端不需要安装PDF阅读器的情况下可以查看内容。

2:对于上传的视频要生成,每一个视频对应的小图.小图从视频中截取,网上也有成熟的方案,ffmpeg,截取视频的针数,和图片大小,生成图片。

 

以上生成的文件测试java代码如下:

package test;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;

public class CmdUtil {

    /**
     *
     * pdf转换为swf文件
     *
     * @param sourcePath
     * @param destPath
     * @param fileName
     * @return
     * @throws Exception
     */
    public static boolean pdfToswf(String fileName, String targetFileName,
            String setPath) {
        List<String> command = new java.util.ArrayList<String>();
        command.add(setPath + "/pdf2swf.exe");
        command.add("-z");
        command.add("-s");
        command.add("-flashversion=9");
        command.add(""+fileName+"");
        command.add("-o");
        command.add(""+targetFileName+"");
        try {
            ProcessBuilder builder = new ProcessBuilder();
            builder.command(command);
            Process pro=builder.start();
        
            BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(pro.getInputStream()));
            while (bufferedReader.readLine() != null) {
            }    
             int i =pro.waitFor();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;

    }
    /**
     *
     * flv截取视频图片
     *
     * @param sourcePath
     * @param destPath
     * @param fileName
     * @return
     * @throws Exception
     */
    public static boolean flvCatchJpg(String fileName, String targetFileName,
            String setPath, String FlvImgSize) {
        try {
            List<String> command = new java.util.ArrayList<String>();
            command.add(setPath + "/ffmpeg.exe");
            command.add("-i");
            command.add(fileName);
            command.add("-y");
            command.add("-f");
            command.add("image2");
            command.add("-ss");
            command.add("5");// 截取图片针数
            command.add("-t");
            command.add("0.001");
            command.add("-s");
            command.add(FlvImgSize);
            command.add(targetFileName);

            ProcessBuilder builder = new ProcessBuilder();
            builder.command(command);
            builder.start();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static void main(String[] args) {

       //需要下载pwd2swf.exe和ffmpeg.exe
        String setPath = "D:/test/convert";//设置转换的运行命令的目录
        String fileName = "D:/test/FreeMarker_Manual_zh_CN.pdf";//原PDF文件
        String targetFileName = "D:/test/freemarker_pdf.swf";//转换后的SWF文件
        boolean flag = CmdUtil.pdfToswf(fileName, targetFileName, setPath);
        System.out.println(flag);
        
        fileName = "D:/test/testflv.flv";//需要截取图片视频    (FVL格式)
        targetFileName = "D:/test/testflv.png";//截取后存储的文件
        String FlvImgSize = "80*60";//截图的图片大小
        boolean flag = CmdUtil.flvCatchJpg(fileName, targetFileName,setPath, FlvImgSize);
        System.out.println(flag);
        
    }
}

posted @ 2012-07-15 00:23  huangzhijun  阅读(451)  评论(0编辑  收藏  举报