我正在尝试仅从许多不同的代码(rtf doc pdf)中提取文本.我自然而然地求助于Apache Tika,因为它可以自动检测文档并相应地提取文本.我只对文本感兴趣,而不对格式感兴趣.
我的应用程序最终出现大量内存泄漏,在进行调查时,这来自于PDFBox依赖项中PDFFont类的缓存.我对从PDF缓存Fontmetrics和其他Font格式问题不感兴趣,因为我只想提取文本.
我正在使用tika 1.12.有谁知道如何解决这个棘手的问题.这就是我使用自动检测的方式:
AutoDetectParser parser = new AutoDetectParser(); BodyContentHandler handler = new BodyContentHandler(-1); Metadata metadata = new Metadata(); FileInputStream inputstream = new FileInputStream(new File(child.getPath())); ParseContext context = new ParseContext(); parser.parse(inputstream, handler, metadata, context); String s=null; s =handler.toString(); handler=null; context=null; inputstream.close(); PDFont.clearResources();解决方案
所以我捏造了一个变通办法,每次文件处理完毕后都调用System.gc();,可以正常使用,但是并不能真正回答问题.
I am trying to extract text only from a number of different coduments (rtf doc pdf). I naturally turned to Apache Tika because it can autodetect the document and extract text accordingly. I am only interested in the text and not formatting etc.
My application ends up with a big memory leak and on investigating it, this is coming from caching from PDFFont class from the PDFBox dependency. I am not interesting in caching Fontmetrics and other Font formatting issues from pdfs as I want to only extract the text.
I am using tika 1.12. Does anyone know how to get around this cahcing issue. This is how I am using Autodetect:
AutoDetectParser parser = new AutoDetectParser(); BodyContentHandler handler = new BodyContentHandler(-1); Metadata metadata = new Metadata(); FileInputStream inputstream = new FileInputStream(new File(child.getPath())); ParseContext context = new ParseContext(); parser.parse(inputstream, handler, metadata, context); String s=null; s =handler.toString(); handler=null; context=null; inputstream.close(); PDFont.clearResources();解决方案
So I fudged a workaround and just called System.gc(); everytime the file had finished being processed which works a treat but doesn't really answer the question.
更多推荐
使用Apache Tika删除PDFont缓存
发布评论