I have this java code:
try {
PDFTextStripper pdfs = new PDFTextStripper();
String textOfPDF = pdfs.getText(PDDocument.load("doc"));
doc.add(new Field(campo.getDestino(),
textOfPDF,
Field.Store.NO,
Field.Index.ANALYZED));
} catch (Exception exep) {
System.out.println(exep);
System.out.println("PDF fail");
}
And throws this:
11:45:07,017 WARN [COSDocument] Warning: You did not close a PDF Document
And I don't know why but throw this 1, 2, 3, or more.
I find that COSDocument is a class and have close() method, but I don't use this class nowhere.
I have this imports:
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;
Thanks :)
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();
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With