阅读多语言 PDF 文件
当 iText 读取 PDF(将页面内容提取为字符串变量)时,内容将通过以下方式修复:
reader = new PdfReader(getResources().openRawResource(R.raw.resume1));
original_content = PdfTextExtractor.getTextFromPage(reader, 2);
String sub_content = original_content.trim().replaceAll(" {2,}", " ");
sub_content = sub_content.trim().replaceAll("\n ", "\n");
sub_content = sub_content.replaceAll("(.+)(?<!\\.)\n(?!\\W)", "$1 ");
如果文档只有 1 列,但如果文档有多列,则每行提取文档 1。它会结合左右列。
我使用这个作为示例 PDF,这是来自 START QA 文档。
如何阅读多语言 PDF 文档?
1 回答
这个问题有两种不同的方法,使用的选择取决于 PDF 本身。
PdfTextExtractor.getTextFromPage
隐式使用的LocationTextExtractionStrategy
,而是使用SimpleTextExtractionStrategy
;在你的情况下:LocationTextExtractionStrategy
,而是使用PdfTextExtractor.getTextFromPage
明确地将一个这样的策略包装在FilteredTextRenderListener
中,限制它接收文本仅适用于单个区域;在你的情况下: