PDF 转成图片

采用 icepdf 实现,具体参考:JAVA中pdf转图片的方法icePDF去水印方法

import org.icepdf.core.pobjects.Document;
import org.icepdf.core.pobjects.Page;
import org.icepdf.core.util.GraphicsRenderingHints;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * PDF 转成 图片
 *
 * @author dongbz
 * @since 2017/7/26
 */
public class Pdf2Image {

    /**
     * PDF 首页转成图片
     *
     * @param input     PDF文件全路径
     * @param output    生成的图片全路径
     */
    public static void firstPage2Image(String input, String output) {
        Document document = new Document();
        document.setFile(input);

        if (document.getNumberOfPages() <= 0) throw new RuntimeException(String.format("%s's pages le 0", input));

        BufferedImage image = (BufferedImage) document.getPageImage(0, GraphicsRenderingHints.SCREEN, Page.BOUNDARY_CROPBOX, 0F, 0.25F);
        File file = new File(output);
        try {
            ImageIO.write(image, "png", file);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        image.flush();

        document.dispose();
    }

}
原文地址:https://www.cnblogs.com/zhiqsyr/p/7240497.html