ITextSharp查找PDF中特定文本的坐标 [英] ITextSharp Find coordinates of specific text in PDF

查看:4054
本文介绍了ITextSharp查找PDF中特定文本的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现很多网站和帖子,问题和我一样,但他们似乎有共同点是人们正在回答他们如何在特定位置插入新文本的例子。我有一个PDF文档由另一个程序生成,我无法控制,它有一行客户端登录,但该行不是绝对的位置,所以我们使用的服务AssureSign将无法正常工作,因为你必须知道签名行的位置在哪里。所以我需要创建一个新的程序,它将找到签名行的位置,并将该信息发送到assureign系统。

I have found many sites and postings that the question is the same as mine but what they all seem to have in common is people are answering them with examples of how to insert new text at specific locations. I have a PDF document that is generated by another program that I have no control over and it has a line for a client to sign on but that line is not in an absolute position so a service that we use called AssureSign will not work properly because you have to know where the position of the signature line is. So I need to create a new program that will find the position of the signature line and send that information to the assuresign system.

这真的应该很简单,但由于某种原因我不会得到它

This really should be simple but for some reason I am not getting it

推荐答案

您可以使用iText(Sharp)的解析器包来查找给定文本的位置。你必须实现你自己的RenderListener,因为该包的主要用例是文本提取,而不是文本位置查找。

You can make use of the parser package of iText (Sharp) to find the position of a given text. You do have to implement your own RenderListener, though, as the main use case of that package is text extraction, not text position finding.

它不是那么容易可能认为如。

It is not as easy as you might think as e.g. the individual characters of the words might come in separately in any order.

PS:

首先,你必须找出,虽然,签名的行是否由字符(如你的问题似乎暗示)或是否是一个绘制的路径。

First you will have to find out, though, whether the line for the signature consists of characters (as your question seems to imply) or whether it is a drawn path. Additionally you will have to find out whether that line is unique in the document.

在前一种情况下,您需要的RenderListener实现需要检查转发用于处理的TextRenderInfo对象在其RenderText方法中。如果其文本内容包含构建signatrue行的那些唯一字符,则必须存储此TextRenderInfo的位置数据。如果行字符不唯一,您必须找到一些额外的标准,使它们是唯一的,例如。

In the former case, the RenderListener implementation you need has to inspect the TextRenderInfo objects forwarded for processing in its RenderText method. If its text content contains those unique characters building the signatrue line, you have to store the position data of this TextRenderInfo. If the line characters are not unique, you will have to find some additional criteria making them unique, e.g. some preceding string or possibly a fact that its the last occurance of those characters in the document.

在后一种情况下,解析器包功能必须在某种程度上扩展,因为它目前不报告路径。根据iText邮件列表,这样的扩展名在ToDo列表中。

In the latter case the parser package functionality has to be somewhat extended as it currently does not report paths. According to the iText mailing list, an extension like that is on the ToDo list.

这篇关于ITextSharp查找PDF中特定文本的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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