GlyphMapping 中的 PDFClown NullPointerException

PDFClown NullPointerException in GlyphMapping

我最近将我的代码从 PDFClown v0.1.2 切换到 v0.1.2.1。我认为我现在已经遇到了一些差异(更改了 TextMarkup() 的构造函数并从 CallOutNote 切换到 StaticNote)但不幸的是我 运行 遇到了一些我还没有弄清楚如何解决的问题它。

这是堆栈跟踪:

Exception in thread "Thread-0" java.lang.ExceptionInInitializerError
at org.pdfclown.documents.contents.fonts.Encoding.put(Encoding.java:88)
at org.pdfclown.documents.contents.fonts.StandardEncoding.<init>(StandardEncoding.java:41)
at org.pdfclown.documents.contents.fonts.Encoding.<clinit>(Encoding.java:54)
at org.pdfclown.documents.contents.fonts.SimpleFont.getBaseEncoding(SimpleFont.java:82)
at org.pdfclown.documents.contents.fonts.SimpleFont.loadEncoding(SimpleFont.java:142)
at org.pdfclown.documents.contents.fonts.SimpleFont.onLoad(SimpleFont.java:170)
at org.pdfclown.documents.contents.fonts.Font.load(Font.java:878)
at org.pdfclown.documents.contents.fonts.Font.<init>(Font.java:368)
at org.pdfclown.documents.contents.fonts.SimpleFont.<init>(SimpleFont.java:65)
at org.pdfclown.documents.contents.fonts.TrueTypeFont.<init>(TrueTypeFont.java:47)
at org.pdfclown.documents.contents.fonts.Font.wrap(Font.java:262)
at org.pdfclown.documents.contents.FontResources.wrap(FontResources.java:72)
at org.pdfclown.documents.contents.FontResources.wrap(FontResources.java:1)
at org.pdfclown.documents.contents.ResourceItems.get(ResourceItems.java:119)
at org.pdfclown.documents.contents.objects.SetFont.getResource(SetFont.java:119)
at org.pdfclown.documents.contents.objects.SetFont.getFont(SetFont.java:83)
at org.pdfclown.documents.contents.objects.SetFont.scan(SetFont.java:97)
at org.pdfclown.documents.contents.ContentScanner.moveNext(ContentScanner.java:1360)
at org.pdfclown.documents.contents.ContentScanner$TextWrapper.extract(ContentScanner.java:819)
at org.pdfclown.documents.contents.ContentScanner$TextWrapper.<init>(ContentScanner.java:771)
at org.pdfclown.documents.contents.ContentScanner$TextWrapper.<init>(ContentScanner.java:764)
at org.pdfclown.documents.contents.ContentScanner$GraphicsObjectWrapper.get(ContentScanner.java:684)
at org.pdfclown.documents.contents.ContentScanner$GraphicsObjectWrapper.access[=10=](ContentScanner.java:676)
at org.pdfclown.documents.contents.ContentScanner.getCurrentWrapper(ContentScanner.java:1184)
at org.pdfclown.tools.TextExtractor.extract(TextExtractor.java:636)
at org.pdfclown.tools.TextExtractor.extract(TextExtractor.java:653)
at org.pdfclown.tools.TextExtractor.extract(TextExtractor.java:653)
at org.pdfclown.tools.TextExtractor.extract(TextExtractor.java:299)
at theproject.logic.WorkerThread.extractTextOfHighlight(WorkerThread.java:758)
at theproject.logic.WorkerThread.run(WorkerThread.java:107)
Caused by: java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:72)
at org.pdfclown.documents.contents.fonts.GlyphMapping.load(GlyphMapping.java:69)
at org.pdfclown.documents.contents.fonts.GlyphMapping.<clinit>(GlyphMapping.java:47)
... 30 more

方法 "extractTextOfHighlight()" 提取文档中突出显示的文本:

protected List<ITextString> extractTextOfHighlight(Rectangle2D rect2d, Page page) {
    TextExtractor extractor = new TextExtractor();

    List<Rectangle2D> areas = new ArrayList<Rectangle2D>();
    areas.add(rect2d);
    extractor.setAreas(areas);
    extractor.setAreaTolerance(2.0);

    Map<Rectangle2D, List<ITextString>> map = extractor.extract(page);
    // Util.printExtractedTextMapToConsole(map);
    for(Rectangle2D keyRect : map.keySet()) {
        return validateExtractedStrings(map.get(keyRect));
    }

    return null;
}

StackExchange 上有一个 post,这是唯一一个描述类似错误的:

我已经在 PDFClown 中应用了推荐的修复程序,但 运行 出现了同样的错误。我的问题是,如果有什么我可以做的来修复这个错误。我真的没主意了。

这是我用于测试的 pdf: https://www.dropbox.com/s/pt32s7gbrvr21a8/testfile.pdf?dl=0

请验证您是否已正确构建 PDF Clown jar。

您的异常最初发生为 NullPointerException

at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:72)
at org.pdfclown.documents.contents.fonts.GlyphMapping.load(GlyphMapping.java:69)
at org.pdfclown.documents.contents.fonts.GlyphMapping.<clinit>(GlyphMapping.java:47)

即在GlyphMapping.load期间

  glyphListStream = new BufferedReader(
    new InputStreamReader(
      GlyphMapping.class.getResourceAsStream("/fonts/AGL20.scsv")
      )
    );

找不到资源 "/fonts/AGL20.scsv"(这导致 getResourceAsStream 到 return nullInputStreamReader 构造函数将其转发给其父 class Reader 构造函数将其参数与 null 进行比较,如果相等则抛出显式 NullPointerException).