1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-14 10:16:21 +00:00

Close all PDDocument

This commit is contained in:
jendib
2013-08-18 14:25:53 +02:00
parent 2c7083aa43
commit 2289f523c4
3 changed files with 16 additions and 10 deletions

View File

@@ -153,12 +153,17 @@ public class FileUtil {
image = ImageIO.read(originalFile);
} else if(file.getMimeType().equals(MimeType.APPLICATION_PDF)) {
// Generate preview from the first page of the PDF
PDDocument pdfDocument = PDDocument.load(originalFile.getAbsolutePath(), true);
@SuppressWarnings("unchecked")
List<PDPage> pageList = pdfDocument.getDocumentCatalog().getAllPages();
if (pageList.size() > 0) {
PDPage page = pageList.get(0);
image = page.convertToImage();
PDDocument pdfDocument = null;
try {
pdfDocument = PDDocument.load(originalFile.getAbsolutePath(), true);
@SuppressWarnings("unchecked")
List<PDPage> pageList = pdfDocument.getDocumentCatalog().getAllPages();
if (pageList.size() > 0) {
PDPage page = pageList.get(0);
image = page.convertToImage();
}
} finally {
pdfDocument.close();
}
}