I recently switched my code from PDFClown v0.1.2 to v0.1.2.1. There were some differences which I think I have already met now (changed constructors of TextMarkup() and switching from CallOutNote to StaticNote) but unfortunately I've run in some troubles which I haven't figured out yet how to fix it.
Here is the stacktrace:
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
The method "extractTextOfHighlight()" extracts the text within a document which is highlighted:
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;
}
There is a post on StackExchange which was the only one describing a similar error:
https://stackoverflow.com/a/23804322
I already applied the recommended fix in PDFClown but ran into the same error. My question is, if there is anything I can do to fix this error. I'm really out of ideas.
Here is the pdf I used for my testing: https://www.dropbox.com/s/pt32s7gbrvr21a8/testfile.pdf?dl=0
Please verify you have built your PDF Clown jar correctly.
Your exception initially occurs as a 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)
i.e. in GlyphMapping.load
during
glyphListStream = new BufferedReader(
new InputStreamReader(
GlyphMapping.class.getResourceAsStream("/fonts/AGL20.scsv")
)
);
the resource "/fonts/AGL20.scsv"
could not be found (which causes getResourceAsStream
to return null
which the InputStreamReader
constructor forwards to its parent class Reader
constructor which compares its parameter with null
and in case of equality throws an explicit NullPointerException
).