使用bytescot PDFExtractor C#查找文本坐标



我有一个PDF,需要查找并替换一些文本。我知道如何创建覆盖和添加文本,但我无法确定如何定位当前文本坐标。这是我在字节侦察网站上找到的例子

// 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();
}
} 

但它不起作用,因为没有一个重载Find方法需要4个参数。我不习惯使用Bytescout从pdf中查找文本坐标,但我的公司有许可证。如果Bytescout不能完成我想要做的事情,有没有一种无许可证的方法可以在pdf上找到文本坐标?

尝试使用:

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

,它具有以下属性:

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

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

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

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

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

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

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

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

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

最新更新