office各种文件转图片



import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.HashMap;
import java.util.Map;

import javax.imageio.ImageIO;

import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.SlideShow;
import org.icepdf.core.pobjects.Document;
import org.icepdf.core.pobjects.Page;
import org.icepdf.core.util.GraphicsRenderingHints;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;



/**
 * 各种文件转图片工具类
 * @author yangcheng.ai
 *
 */
public class ImageUtil {
    
    private static Logger log = LoggerFactory.getLogger(ImageUtil.class);
    
    public static Map<String, String> dirMap = new HashMap<String, String>();
    
    
    /**
     * 获取PDF文件转成图片后的数量
     * @param pdfPath
     * @return
     */
    public static Integer getPdfFileSize(String pdfPath){
        Integer size = 0;
        try {
            File file = new File(pdfPath);  
            RandomAccessFile raf = new RandomAccessFile(file, "r");  
            FileChannel channel = raf.getChannel();  
            MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY,  
                    0, channel.size());  
            PDFFile pdffile = new PDFFile(buf);
            size = pdffile.getNumPages();
        } catch (Exception e) {
            log.error("文件读取失败!");
            e.printStackTrace();
        }
        return size;
    }

    /**
     * PDF转JPG
     * @param pdfPath
     * @return
     */
    public static String pdfToJpg(String pdfPath){
        boolean checkStatus = false;
        String picPath = pdfPath.split("\\.")[0];
        File dir = new File(picPath);
        if(!dir.exists()){
            dir.mkdir();
            checkStatus = true;
            log.info(pdfPath + "目标文件不存在,准备生成...");
        }else{
            File pdfFile = new File(pdfPath);
            if((pdfFile.lastModified() - dir.lastModified()) > 0){
                checkStatus = true;
                deleteFile(dir);
                log.info(pdfPath + "目标文件有修改,准备生成...");
            }
        }
        
        if(checkStatus){
            int i = 0;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值