Using Apache PDFBox and once the PDF file is uploaded use this method that loads the uploaded document from a path, takes the first page, converts it into an image and saves it into a path of your choice. Save this path in your DB record.
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.imageio.ImageIO;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
public class PDFUtil {
public static void saveFirstPageThumbnail() throws IOException {
PDDocument document = PDDocument.load("C:\\testbook.pdf");
List<PDPage> pages = document.getDocumentCatalog().getAllPages();
PDPage page = pages.get(0); //first one
BufferedImage bufferedImage = page.convertToImage();
File outputFile = new File( "C:\\image.jpg");
ImageIO.write(bufferedImage, "jpg", outputFile);
}
}
Later on when you're required to print links just return the path of your created image in the callback and form your link in normal html:
<a href="path/to/document.pdf"><img src="path/to/image.jpg" /></a>
and here's the library dependency if you're using maven
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.8.2</version>
</dependency>