PDF 中的多选表单字段

发布于 2024-08-27 22:34:41 字数 798 浏览 6 评论 0原文

使用 PDF,是否可以创建具有多个字段(其中多个字段可以选择)的单个表单元素?例如,在 HTML 中,可以创建一组与相同字段名称关联的复选框:

<div>Select one for Member of the School Board</div>
<input type="checkbox" name="field(school)" value="vote1">
<span class="label">Libby T. Garvey</span><br/>
<input type="checkbox" name="field(school)" value="vote2">
<span class="label">Emma N. Violand-Sanchez</span><br/>

在本例中,字段名称为“field(school)”,提交表单时可将“field(school)”供给 0、1 或 2 次。

PDF 中是否有等效的构造,其中单个字段可以有多个值。到目前为止,在我的调查中,似乎如果为字段指定了相同的名称,则只能选择一个字段。如果可以在 PDF 中实现这一点,那么这个结构叫什么以及如何实现?

编辑:为了澄清,我知道 PDF 可以包含具有不同字段名称的多个表单字段,并且可以独立选择这些字段,但分组是隐式的,而不是像 HTML 表单那样显式。我想使用一种使选项分组明确的构造,并且最好允许限制(例如,至少需要一个,允许不超过 2 个,等等)。

编辑:如果有人能找到一个权威的意见来证明这是不可能的,那也是一个理想的答案。

Using PDF, is it possible to create a single form element with multiple fields of which several can be selected? For example, in HTML, one can create a set of checkboxes associated with the same field name:

<div>Select one for Member of the School Board</div>
<input type="checkbox" name="field(school)" value="vote1">
<span class="label">Libby T. Garvey</span><br/>
<input type="checkbox" name="field(school)" value="vote2">
<span class="label">Emma N. Violand-Sanchez</span><br/>

In this case, the field name is "field(school)", and when the form is submitted, "field(school)" can be supplied 0, 1, or 2 times.

Is there an equivalent construct in PDF where a single field can have multiple values. So far in my investigation, it appears that if fields are assigned the same name, it is only possible to select one field. If it is possible to implement this in PDF, what is this construct called and how can it be implemented?

Edit: To clarify, I am aware that a PDF can contain multiple form fields with different field names, and those can be selected independently, but then the grouping is implicit and not explicit as with the HTML form. I would like to use a construct that makes the grouping of options explicit, and preferably allows for restrictions (e.g. at least one required, no more than 2 allowed, etc).

Edit: If someone can find an authoritative opinion that this is not possible, that would also be a desirable answer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晚雾 2024-09-03 22:34:41

是的,这是可能的。在 Adob​​e PDF 中,您有复选框概念和单选按钮概念。虽然每个复选框和单选按钮都可以有自己的名称,但它们也可以通过 GroupName.subobj 通过子层进行分组。

Adobe对此的描述如下:

字段名称。这可能包括
分层语法以便
促进逻辑分组。为了
例如,名称 myGroup.firstField
意味着表单字段firstField
属于一组称为
我的组。创造的优势
逻辑层次结构是你可以
强制执行之间的一致性
相关表单字段的属性
设置组的属性,
它会自动传播到所有
组内的表单字段。

当通过层次结构设置字段时,您可以在本例中获取 myGroup 的值,并返回该组的选定值。同样,对于单选按钮,您需要确保组中的所有字段都具有相同的名称。

这种创建表单字段的方法
适用于所有领域,但是
应该注意的是单选按钮
需要特殊处理。既然一套
的单选按钮代表一组
相互排斥的选择,他们
属于同一组。由于
this,所有单选按钮的名称
同一组中的值必须相同。
此外,出口额

单选按钮组必须设置为
一条语句,其中一个数组
的值由
字段的exportValues属性
目的。例如,假设我们将
喜欢创建一套三台收音机
按钮,每个 12 点宽,12
点高了,全部命名为myRadio。我们
将把它们放在第 5 页
文件,其出口价值将
是、否和取消。他们可以是
如给出的代码所示创建
如下:

var name = "myRadio";
var type = "radiobutton";
var page = 5;
var rb = this.addField(name, type, page, [400, 442, 412, 430]);
this.addField(name, type, page, [400, 427, 412, 415]);
this.addField(name, type, page, [400, 412, 412, 400]);
rb.exportValues=["Yes", "No", "Cancel"];

Yes it is possible. In Adobe PDFs you have the checkbox concept and the radio button concept. While each checkbox and radio button can have its own name, however, they can also be grouped through a subtier via the GroupName.subobj.

Adobe describes it as follows:

The field name. This may include
hierarchical syntax in order to
facilitate logical groupings. For
example, the name myGroup.firstField
implies that the form field firstField
belongs to a group of fields called
myGroup. The advantage of creating
logical hierarchies is that you can
enforce consistency among the
properties of related form fields by
setting the properties of the group,
which automatically propagate to all
form fields within the group.

When the fields are set via a hierarchy you can then get the value of myGroup in this case, and return the selected value of the group. Similarly in the case of RadioButtons you would make sure that all fields in a group have the same name.

This approach to creating form fields
is applicable to all fields, but it
should be noted that radio buttons
require special treatment. Since a set
of radio buttons represents a set of
mutually exclusive choices, they
belong to the same group. Because of
this, the names of all radio buttons
in the same group must be identical.
In addition, the export values of the

set of radio buttons must be set with
a single statement, in which an array
of values are assigned by the
exportValues property of the Field
object. For example, suppose we would
like to create a set of three radio
buttons, each 12 points wide and 12
points high, all named myRadio. We
will place them on page 5 of the
document, and their export values will
be Yes, No, and Cancel. They can be
created as shown in the code given
below:

var name = "myRadio";
var type = "radiobutton";
var page = 5;
var rb = this.addField(name, type, page, [400, 442, 412, 430]);
this.addField(name, type, page, [400, 427, 412, 415]);
this.addField(name, type, page, [400, 412, 412, 400]);
rb.exportValues=["Yes", "No", "Cancel"];
独夜无伴 2024-09-03 22:34:41

asnyder 的回应让我得出这样的结论:没有一种自动方法可以处理单个字段中的多个值(就像 HTML 一样)。 asnyder 的示例来自使用 JavaScript 开发 Acrobat 应用程序,可从 Acrobat Javascript 开发人员中心。本文档提供了一些如何操作复选框、组合框和单选按钮的示例。所有示例都阐明了该问题,并最终使我得出结论:任何使用 PDF 表单的系统都将隐式定义任何多选组。

使用 groupName.fieldName 的构造对于将小部件作为一个组进行操作(在 Acrobat Javascript 中)似乎很有用,但是无法枚举组的字段(无需枚举所有字段并过滤 groupName),并且如果不以编程方式检查值,则无法确定该组。

换句话说,多选值在任何实质上都不是 Acrobat 或 PDF 的固有特征,尽管可以通过编程实现这种形式。

asnyder's response led me to the conclusion that there is no automatic way to handle multiple values within a single field (as one can with HTML). asnyder's examples come from Developing Acrobat Applications Using JavaScript, available from the Acrobat Javascript Developer Center. This document provides some examples of how to manipulate checkboxes, combo boxes, and radio buttons. All of the examples shed some light on the problem and ultimately led me to the conclusion that any system that is using PDF forms will have any multi-selectable groups implicitly defined.

Using the construct of groupName.fieldName appears to be useful to manipulate the widgets as a group (in Acrobat Javascript), but the fields of a group cannot be enumerated (without enumerating all fields and filtering for the groupName), and the collective value of that group cannot be determined without programatically inspecting the values.

In other words, a multi-selectable value is not an intrinsic feature of Acrobat nor of PDF in any substantial way, though it is possible to implement such a form through programming.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文