I can't delete pdf file after working with PdfBox. All closeable variables are closed, but it not helped. I can't delete pdf file anywhere and anyhow, when my app launch method with PdfBox library.
public void generateTxtFromPDF(String txtFile, String pdfFile) throws IOException {
COSDocument cosDoc = null;
PDDocument document = null;
PrintWriter pw = null;
try {
File f = new File(pdfFile);
String parsedText;
PDFParser parser = new PDFParser(new RandomAccessFile(f, "r"));
parser.parse();
cosDoc = parser.getDocument();
PDFTextStripper pdfStripper = new PDFTextStripper();
document = new PDDocument(cosDoc);
parsedText = pdfStripper.getText(document);
pw = new PrintWriter(txtFile);
pw.print(parsedText);
} catch (IOException e) {
log.error(e.getMessage());
e.printStackTrace();
} finally {
if (pw != null) {
pw.close();
}
if (document != null) {
try {
document.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (cosDoc != null) {
cosDoc.close();
}
}
}
maybe, somebody know what is wrong?