pdf转图片

 
            org.apache.pdfbox
            pdfbox
            2.0.18
        
        
            org.apache.pdfbox
            jbig2-imageio
            3.0.2
        
        
            org.apache.pdfbox
            pdfbox-tools
            2.0.18
        
@Test
    public void pdf2image2() throws IOException {

        PDDocument pdDocument;
        FileInputStream fileInputStream = new FileInputStream("d:/test.pdf");
        pdDocument = PDDocument.load(fileInputStream);
        PDFRenderer renderer = new PDFRenderer(pdDocument);
        // 获取PDF页数
        int pages = pdDocument.getNumberOfPages();
        for (int i = 0; i < pages; i++) {
            BufferedImage image = renderer.renderImage(i, 2.5f, ImageType.BINARY, RenderDestination.PRINT);
            FileOutputStream out = new FileOutputStream("d:\\imageresult" + i + ".png");
            // PNG
            ImageIO.write(image, "png", out);

        }
        pdDocument.close();

    }

使用renderImage会小很多

你可能感兴趣的