tech.chakapoko.com
Home / Java / Apache PDFBox

[Java]PDFBoxでPDFを画像に変換する

package com.example;

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

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

public class PDFBoxExample {

    public static void main(String[] args) throws IOException {
        try(PDDocument document = PDDocument.load(new File("Example.pdf"))) {
            PDFRenderer renderer = new PDFRenderer(document);
            int pageIndex = 0;
            BufferedImage bufferedImage = renderer.renderImage(pageIndex);
            ImageIO.write(bufferedImage, "jpg", new File("Example.jpg"));
        }
    }

}