c# - 如何从特定矩形区域内的 pdf 文档中提取文本?

标签 c# pdf

<分区>

我必须从特定矩形区域内的 pdf 文档中提取文本。工作流程如下。首先将pdf转换为jpg图像。然后用户在图片顶部绘制选择矩形。然后我需要以某种方式从该选择区域内的 pdf 文档中提取所有文本。有什么建议可以使用可从 C# 访问的免费软件 pdf 库吗?

最佳答案

这段代码将使用itextsharp在直角坐标的基础上完美提取pdf数据

    List<string> linestringlist = new List<string>();
    PdfReader reader = new PdfReader(pdfFilename);
    iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(coordinate1, coordinate2, coordinate3, coordinate4);
    RenderFilter[] renderFilter = new RenderFilter[1];
    renderFilter[0] = new RegionTextRenderFilter(rect);
    ITextExtractionStrategy textExtractionStrategy = new FilteredTextRenderListener(new LocationTextExtractionStrategy(), renderFilter);
    string text = PdfTextExtractor.GetTextFromPage(reader, 1, textExtractionStrategy);

关于c# - 如何从特定矩形区域内的 pdf 文档中提取文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4297931/

相关文章:

c# - 如何制作 'always-on-bottom' -window

c# - 如何在较长的 Storyboard 中的 DoubleAnimation 末尾调用回调?

c# - 将 ViewData 传递给部分 View

c# - 如何通过 REST API 发送文件?

javascript - 为什么带有 pdf 文件的 &lt;iframe&gt; 没有显示在页面上?

php - 命令行后脚本不继续

c# - react 性扩展示例或限制?

c# - .NET httpclient 不一致地保存 pdf 文件

ms-access - Crystal Reports 11 - 添加了无用的空白页,仅添加了包含数据的组标题

node.js - Node js - 快速发送 pdf 作为响应下载