Here's a code snippet. It iterates over all the PDF files in a directory, captures an image of the first page and writes it out as a jpg.
Maven dependencies:
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>3.0.7</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox-tools</artifactId>
<version>3.0.7</version>
</dependency
Code:
final static int PAGE = 0;
final static int DPI = 96;
File dir = new File("....");
Collection<File> files = FileUtils.listFiles(dir, new String[] { "pdf" }, false);
for (File file : files) {
PDDocument document = Loader.loadPDF(file);
PDFRenderer renderer = new PDFRenderer(document);
BufferedImage image = renderer.renderImageWithDPI(PAGE, DPI, ImageType.RGB);
String outputPrefix = FilenameUtils.removeExtension(file.getAbsolutePath());
String fileName = outputPrefix + ".jpg";
ImageIOUtil.writeImage(image, fileName, DPI, 1f);
}
Let me know if you want more complete/details. Thanks for considering this feature.
(sorry for the poor/lack of indenting)
Edited by: breisachers on 25 Mar 2026, 13:56
Edited by: JeffTucker on 25 Mar 2026, 17:38, to add "code" tags