通过acrokey查找字段绝对位置和尺寸 [英] Find field absolute position and dimension by acrokey

查看:342
本文介绍了通过acrokey查找字段绝对位置和尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于一个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查找字段绝对位置和尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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