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();
}
}

View File

@ -251,15 +251,15 @@ public class DocumentResource extends BaseResource {
if (params[1].length() == 10) {
DateTime date = dayFormatter.parseDateTime(params[1]);
documentCriteria.setCreateDateMin(date.toDate());
documentCriteria.setCreateDateMax(date.plusDays(1).toDate());
documentCriteria.setCreateDateMax(date.plusDays(1).minusSeconds(1).toDate());
} else if (params[1].length() == 7) {
DateTime date = monthFormatter.parseDateTime(params[1]);
documentCriteria.setCreateDateMin(date.toDate());
documentCriteria.setCreateDateMax(date.plusMonths(1).toDate());
documentCriteria.setCreateDateMax(date.plusMonths(1).minusSeconds(1).toDate());
} else if (params[1].length() == 4) {
DateTime date = yearFormatter.parseDateTime(params[1]);
documentCriteria.setCreateDateMin(date.toDate());
documentCriteria.setCreateDateMax(date.plusYears(1).toDate());
documentCriteria.setCreateDateMax(date.plusYears(1).minusSeconds(1).toDate());
}
} catch (IllegalArgumentException e) {
// NOP

View File

@ -2,4 +2,5 @@ log4j.rootCategory=WARN, MEMORY
log4j.appender.MEMORY=com.sismics.util.log4j.MemoryAppender
log4j.appender.MEMORY.size=1000
log4j.logger.com.sismics=INFO
log4j.logger.com.sismics=INFO
log4j.logger.org.apache.pdfbox=ERROR