8

私はこのJavaコードを持っています:

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、またはそれ以上投げます。

COSDocumentはクラスであり、close()メソッドがあることがわかりましたが、このクラスはどこにも使用していません。

私はこの輸入品を持っています:

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;

ありがとう :)

4

3 に答える 3

16

をロードしていますPDDocumentが、閉じていません。私はあなたがする必要があると思う:

String textOfPdf;
PDDocument doc = PDDocument.load("doc");
try {
    textOfPdf = pdfs.getText(doc);
} finally {
    doc.close();
}
于 2011-02-11T11:35:36.447 に答える
5

この警告は、PDF ドキュメントがファイナライズされ、閉じられていない場合に発生します。

COSDocumentfinalizeメソッドは次のとおりです。

/**
 * Warn the user in the finalizer if he didn't close the PDF document. The method also
 * closes the document just in case, to avoid abandoned temporary files. It's still a good
 * idea for the user to close the PDF document at the earliest possible to conserve resources.
 * @throws IOException if an error occurs while closing the temporary files
 */
protected void finalize() throws IOException
{
    if (!closed) {
        if (warnMissingClose) {
            log.warn( "Warning: You did not close a PDF Document" );
        }
        close();
    }
}

この警告を取り除くには、close作業が完了したときにドキュメントを明示的に呼び出す必要があります。

于 2011-02-11T11:41:09.553 に答える