Java close PDF error
Just had this issue, too. With Java 7 you can do this:
try(PDDocument document = PDDocument.load(input)) {
// do something
} catch (IOException e) {
e.printStackTrace();
}
Because PDDocument implements Closeable
, the try
block will automagically call its close()
method at the end.
You're loading a PDDocument
but not closing it. I suspect you need to do:
String textOfPdf;
PDDocument doc = PDDocument.load("doc");
try {
textOfPdf = pdfs.getText(doc);
} finally {
doc.close();
}