pdf转图片程序(java实现)

所需要的jar包如下,可自行从maven官网上下载


所需要的jar包
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.imageio.ImageIO;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;

public class Test {

    public static void main(String[] args){
        String filePath = "D://test.pdf";
        List imageList = pdfToImagePath(filePath);
        Iterator iterator = imageList.iterator();
        while(iterator.hasNext()){
 
            System.out.println(iterator.next());
        }
//        pdfToImage(filePath);
    }
    public static List pdfToImagePath(String filePath){
        List list = new ArrayList<>();
        String fileDirectory = filePath.substring(0,filePath.lastIndexOf("."));//获取去除后缀的文件路径
 
        String imagePath;
        File file = new File(filePath);
        try {
            File f = new File(fileDirectory);
            if(!f.exists()){
                f.mkdir();
            }
            PDDocument doc = PDDocument.load(file);
            PDFRenderer renderer = new PDFRenderer(doc);
            int pageCount = doc.getNumberOfPages();
            for(int i=0; i

你可能感兴趣的:(pdf转图片程序(java实现))