Getting a preview image of a PDF file in Scala

In order to have an preview image of an PDF file you can use PDFBox. Here is the simple tutorial to extracting an preview image of an PDF file.

Firstly you need to get the pdfbox-jar file & you can get it here.

1. You need to have these following imports.

2. Convert the file in to InputStream.


3. Pass the generated inputstream to PDFDocumentReader & set the page no. of which you want to have an image.

4. Use ImageIO in order to read the resource details from PDFDocumentReader as ByteArrayInputStream & write the generated preview image to desired location.

Get the complete code file here :

Leave a Reply

%d bloggers like this: