通过acrokey查找字段绝对位置和尺寸

编程入门 行业动态 更新时间:2024-10-27 06:21:28
本文介绍了通过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查找字段绝对位置和尺寸

本文发布于:2023-10-08 08:51:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472118.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   尺寸   位置   acrokey

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!