【问题标题】:Finding text coordinates using bytescout PDFExtractor C#使用 bytescout PDFExtractor C# 查找文本坐标
【发布时间】:2020-04-03 16:34:31
【问题描述】:

我有一个 PDF,我需要查找并替换一些文本。我知道如何创建叠加层和添加文本,但我无法确定如何定位当前文本坐标。这是我在 bytescout 网站上找到的示例 -

        // Create Bytescout.PDFExtractor.TextExtractor instance
        TextExtractor extractor = new TextExtractor();
        extractor.RegistrationName = "";
        extractor.RegistrationKey = "";

        /////find text
        // Load sample PDF document
        extractor.LoadDocumentFromFile(@"myPdf.pdf");

        int pageCount = extractor.GetPageCount();
        RectangleF location;

        for (int i = 0; i < pageCount; i++)
        {
            // Search each page for string
            if (extractor.Find(i, "OPTION 2", false, out location))
            {
                do
                {
                    Console.WriteLine("Found on page " + i + " at location " + location.ToString());

                }
                while (extractor.FindNext(out location));
            }
        }
        Console.WriteLine();
        Console.WriteLine("Press any key to continue...");
        Console.ReadLine();
    }
} 

但它不起作用,因为没有采用 4 个参数的重载 Find 方法。我不喜欢使用 Bytescout 从 pdf 中查找文本坐标,但我的公司有许可证。如果 Bytescout 无法完成我正在尝试做的事情,是否有一种免费的方式可以在 pdf 上查找文本坐标?

【问题讨论】:

    标签: c# pdf coordinates pdf-extraction


    【解决方案1】:

    尝试使用:

    extractor.Find(i, "OPTION 2", false).FoundText.Bounds
    

    (来源:https://cdn.bytescout.com/help/BytescoutPDFExtractorSDK/html/M_Bytescout_PDFExtractor_TextExtractor_Find.htm

    FoundText 属性实现了 ISearchResult: https://cdn.bytescout.com/help/BytescoutPDFExtractorSDK/html/T_Bytescout_PDFExtractor_ISearchResult.htm

    具有以下属性:

    公共属性Bounds:所有搜索结果元素的边界矩形。使用 Elements 或 GetElement(Int32) 获取单个元素的边界。

    公共属性 ElementCount: 返回单个搜索结果元素的计数。

    公共属性元素: 搜索结果元素(包含在搜索结果中的单个文本对象)对于 COM/ActiveX,请改用 GetElement(Int32)。

    公共属性Height:搜索结果边框的高度。使用 Elements 或 GetElement(Int32) 获取单个元素的边界。

    公共属性Left:搜索结果边框的左坐标。使用 Elements 或 GetElement(Int32) 获取单个元素的边界。

    公共属性PageIndex:包含搜索结果的页面的索引。

    公共属性文本:搜索结果的文本表示。使用 Elements 或 GetElement(Int32) 获取单个元素。

    公共属性Top:搜索结果边框的顶部坐标。使用 Elements 或 GetElement(Int32) 获取单个元素的边界。

    公共属性Width:搜索结果边框的宽度。使用 Elements 或 GetElement(Int32) 获取单个元素的边界。

    【讨论】:

      猜你喜欢
      • 2012-09-07
      • 2013-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-10
      相关资源
      最近更新 更多