使用iTextSharp获取指定区域中包含的文本 [英] Get text occurrences contained in a specified area with iTextSharp

查看:365
本文介绍了使用iTextSharp获取指定区域中包含的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 iTextSharp 获取pdf文档指定区域中包含的所有文本?

Is it possible, using iTextSharp, get all text occurrences contained in a specified area of ​​a pdf document?

谢谢。

推荐答案

首先,您需要用红色标记的矩形的实际坐标。在视线上,我会说x值144(2英寸)可能是正确的,但如果y值为76,我会感到惊讶,所以你必须仔细检查。

First you need the actual coordinates of the rectangle you marked in Red. On sight, I'd say the x value 144 (2 inches) is probably about right, but it would surprise me if the y value is 76, so you'll have to double check.

一旦你有了矩形的精确坐标,就可以使用 LocationTextExtractionStrategy 来使用iText的文本提取功能,就像在 ExtractPageContentArea 示例。

Once you have the exact coordinates of the rectangle, you can use iText's text extraction functionality using a LocationTextExtractionStrategy as is done in the ExtractPageContentArea example.

对于iTextSharp版本的此示例,请参阅第15章示例的C#端口。

For the iTextSharp version of this example, see the C# port of the examples of chapter 15.

System.util.RectangleJ rect = new System.util.RectangleJ(70, 80, 420, 500);
RenderFilter[] filter = {new RegionTextRenderFilter(rect)};
ITextExtractionStrategy strategy = new FilteredTextRenderListener(
        new LocationTextExtractionStrategy(), filter);
text = PdfTextExtractor.GetTextFromPage(reader, 1, strategy);

这篇关于使用iTextSharp获取指定区域中包含的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆