有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java PDFBox无法正确读取

我试图使用PDFBox阅读PDF文档,但遇到了两个问题:

1)文件有时根本无法阅读。我的一些文件是2005年的,这会影响阅读能力吗?如果有,有什么解决办法吗

2)我在运行代码时收到以下警告,为什么

警告:

log4j:WARN No appenders could be found for logger (org.apache.pdfbox.pdfparser.PDFObjectStreamParser).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

我的方法:

public String readPDF(String companyNumber){

    File file = new File("/users/josh/Documents/2017-8495/"+companyNumber);

          String docText = null;

          try {
            PDFTextStripper stripper = new PDFTextStripper();
            docText = stripper.getText(PDDocument.load(file));

          }catch (Exception e){
              System.out.println(e.getMessage());
          }
          return docText;

}

共 (0) 个答案