简体   繁体   English

Java-使用PDFTextStream时出错

[英]Java - Error while using PDFTextStream

I have a PDF file and want to extract text from it. 我有一个PDF文件,想从中提取文本。 I am using PDFTextStream. 我正在使用PDFTextStream。 I got this code from its documentation, but it gives error. 我从其文档中获得了此代码,但它给出了错误。

import com.snowtide.PDF;
import com.snowtide.pdf.Document;
import com.snowtide.pdf.OutputTarget;

public class ExtractText {
  public static void main (String[] args) throws java.io.IOException {
   // String pdfFilePath = args[0];

    Document pdf = PDF.open("data/bill.pdf");
    StringBuilder text = new StringBuilder(1024);
    pdf.pipe(new OutputTarget(text));
    pdf.close();
    System.out.println(text);
  }
}

This is the error: 这是错误:

Exception in thread "main" java.lang.NullPointerException
    at com.snowtide.pdf.e.b(SourceFile:2740)
    at com.snowtide.pdf.e.a(SourceFile:2691)
    at com.snowtide.pdf.e.c(SourceFile:2642)
    at com.snowtide.pdf.e.a(SourceFile:2059)
    at com.snowtide.pdf.e.c(SourceFile:2108)
    at com.snowtide.pdf.e.a(SourceFile:1950)
    at com.snowtide.pdf.e.a(SourceFile:1755)
    at com.snowtide.pdf.e.a(SourceFile:1820)
    at com.snowtide.pdf.e.pipe(SourceFile:468)
    at ExtractText.main(ExtractText.java:12)

I am using PDFTextStream version 3.3.1. 我正在使用PDFTextStream版本3.3.1。 Line 12 is this: 第12行是这样的:

pdf.pipe(new OutputTarget(text));

The Pdf file should be corrupted or something... there is no way to reproduce the error. Pdf文件应该已损坏或某些东西……无法重现该错误。 Try with another pdf file 尝试使用其他pdf文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM