diff --git a/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java b/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java index a233c3f7..7567049e 100644 --- a/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java +++ b/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java @@ -52,19 +52,20 @@ public class ZUGFeRDImporter { public void extract(String pdfFilename) { - PDDocument doc; + PDDocument doc = null; try { doc = PDDocument.load(pdfFilename); // PDDocumentInformation info = doc.getDocumentInformation(); - PDEmbeddedFilesNameTreeNode etn; PDDocumentNameDictionary names = new PDDocumentNameDictionary( doc.getDocumentCatalog()); + PDEmbeddedFilesNameTreeNode etn; etn = names.getEmbeddedFiles(); - Map efMap = etn.getNames(); - // String filePath = "/tmp/"; - if (efMap==null) { + if (etn==null) { + doc.close(); return; } + Map efMap = etn.getNames(); + // String filePath = "/tmp/"; for (String filename : efMap.keySet()) { /** * currently (in the release candidate of version 1) only one @@ -93,6 +94,13 @@ public class ZUGFeRDImporter { // TODO Auto-generated catch block e1.printStackTrace(); } + finally { + try { + if(doc!=null) { + doc.close(); + } + } catch (IOException e) {} + } }