Update ZUGFeRDImporter.java

corrections for attachmentless pdfs, courtesy by Uwe Mock
This commit is contained in:
Jochen Staerk
2014-06-15 17:36:11 +02:00
committed by jstaerk
parent 6d209be70a
commit dad4131397

View File

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