iTextSharp 可以很好地从 PDF 文档中提取纯文本,但我在处理技术文档中常见的下标/上标文本时遇到了问题。
TextChunk.SameLine()要求两个块具有相同的垂直位置才能位于同一行“上”,而上标或下标文本则不是这种情况。例如,在本文件第 11 页的“燃烧效率”下:
http://www.mass.gov/courts/docs/lawlib/300-399cmr/310cmr7.pdf
预期文本:
monoxide (CO) in flue gas in accordance with the following formula: C.E. = [CO2 /(CO + CO2)]
Run Code Online (Sandbox Code Playgroud)
结果文本:
monoxide (CO) in flue gas in accordance with the following formula: C.E. = [CO /(CO + CO )]
2 2
Run Code Online (Sandbox Code Playgroud)
我转向SameLine()并为其读取的LocationTextExtractionStrategy私有属性创建了公共吸气剂。TextChunk这允许我在我自己的子类中动态调整容差,如下所示:
public class SubSuperStrategy : LocationTextExtractionStrategy {
public int SameLineOrientationTolerance { get; set; }
public int SameLineDistanceTolerance { get; set; }
public override bool …Run Code Online (Sandbox Code Playgroud)