Java关闭PDF错误 [英] Java close PDF error
本文介绍了Java关闭PDF错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下Java代码:
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");
}
并抛出:
11:45:07,017 WARN [COSDocument] Warning: You did not close a PDF Document
我不知道为什么,但是扔掉这个1、2、3或更多.
And I don't know why but throw this 1, 2, 3, or more.
我发现COSDocument是一个类,并且具有close()方法,但是我不会在任何地方使用此类.
I find that COSDocument is a class and have close() method, but I don't use this class nowhere.
我有这个进口:
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;
谢谢:)
推荐答案
您正在加载PDDocument
,但没有将其关闭.我怀疑您需要这样做:
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();
}
这篇关于Java关闭PDF错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文