From 9c5045333efe6b2910600d6e595c86dee90856c3 Mon Sep 17 00:00:00 2001 From: Silvano Trinchero Date: Tue, 10 Apr 2018 17:12:02 +0200 Subject: [PATCH] Fix chiusura file nel merge dei pdf --- .../src/org/adempiere/webui/apps/AEnv.java | 51 ++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java index ec5f896301..034b53b650 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.lang.ref.WeakReference; import java.net.URI; import java.net.URISyntaxException; +import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.List; @@ -592,27 +593,43 @@ public final class AEnv DocumentException, FileNotFoundException { Document document = null; PdfWriter copy = null; - for (File f : pdfList) - { - PdfReader reader = new PdfReader(f.getAbsolutePath()); - if (document == null) + + List pdfReaders = new ArrayList(); + + try + { + for (File f : pdfList) { - document = new Document(reader.getPageSizeWithRotation(1)); - copy = PdfWriter.getInstance(document, new FileOutputStream(outFile)); - document.open(); + PdfReader reader = new PdfReader(f.getAbsolutePath()); + + pdfReaders.add(reader); + + if (document == null) + { + document = new Document(reader.getPageSizeWithRotation(1)); + copy = PdfWriter.getInstance(document, new FileOutputStream(outFile)); + document.open(); + } + int pages = reader.getNumberOfPages(); + PdfContentByte cb = copy.getDirectContent(); + for (int i = 1; i <= pages; i++) { + document.newPage(); + copy.newPage(); + PdfImportedPage page = copy.getImportedPage(reader, i); + cb.addTemplate(page, 0, 0); + copy.releaseTemplate(page); + } } - int pages = reader.getNumberOfPages(); - PdfContentByte cb = copy.getDirectContent(); - for (int i = 1; i <= pages; i++) { - document.newPage(); - copy.newPage(); - PdfImportedPage page = copy.getImportedPage(reader, i); - cb.addTemplate(page, 0, 0); - copy.releaseTemplate(page); + document.close(); + } + finally + { + for(PdfReader reader:pdfReaders) + { + reader.close(); } } - document.close(); - } + } /** * Get window title