鉴于一个acrokey,是否有可能找到该特定字段的绝对位置和维度(getLeft,getTop,getWidth,getHeight)?
Given an acrokey, is it possible to find the absolute position and dimension of that particular field (getLeft, getTop, getWidth, getHeight) ?
反之亦然可能 - 如果我知道这个位置,我可以获得该字段的大小吗?
And is the viceversa possible - if I know the position, can I get the acrokey of the field?
推荐答案你问题的第一部分:
假设您有一个 AcroFields 实例(表单),从 PdfReader (只读)或 PdfStamper 实例中检索,然后就可以了获取与特定字段 name 对应的第一个窗口小部件的字段位置,如下所示:
Suppose that you have an AcroFields instance (form), either retrieved from a PdfReader (read only) or a PdfStamper instance, then you can get the field position of the first widget that corresponds with a specific field name like this:
Rectangle rectangle = form.getFieldPositions(name).get(0).position;请注意,一个字段可以与多个小部件对应。例如,要获取第二个小部件,您需要:
Note that one field can correspond with multiple widgets. For instance, to get the second widget, you need:
Rectangle rectangle = form.getFieldPositions(name).get(1).position;当然:您可能还想知道页码:
Of course: you probably also want to know the page number:
int page = form.getFieldPositions(name).get(0).page;问题的第二部分
字段对应于窗口小部件注释。如果您知道窗口小部件注释的页码,则可以获取页面字典并检查 / Annots 数组的条目。您必须遍历不同的注释,检查每个注释的 / Rect 条目。找到匹配项后,您需要抓取与注释对应的字段的内容。这比在本网站的代码示例中提供的工作更多。
Fields correspond with widget annotations. If you know the page number of the widget annotation, you could get the page dictionary and inspect the entries of the /Annots array. You'll have to loop over the different annotations, inspecting each annotation's /Rect entry. Once you find a match, you need to crawl the content for the field that corresponds with the annotation. That's more work than can be provided in a code sample on this site.
更多推荐
通过acrokey查找字段绝对位置和尺寸
发布评论