我最近将代码从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$0(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上有一篇文章是唯一描述类似错误的文章:

https://stackoverflow.com/a/23804322

我已经在PDFClown中应用了推荐的修复程序,但是遇到了同样的错误。我的问题是,是否有什么办法可以解决此错误。我真的没有主意。

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

最佳答案

请验证您是否正确构建了PDF小丑罐。

您的异常最初以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返回nullInputStreamReader构造函数将其转发到其父类Reader构造函数,该父类将其参数与null进行比较,如果相等,则抛出显式NullPointerException)。

关于java - GlyphMapping中的PDFClown NullPointerException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38997384/

10-12 04:38