gpt4 book ai didi

javascript - pdf 中的重复字段 - Javascript

转载 作者:行者123 更新时间:2023-12-02 23:31:18 35 4
gpt4 key购买 nike

我有一个 pdf 文件,用户需要从中填写。需要根据先前字段中输入的数字复制字段(请参见下面的屏幕截图)

enter image description here

例如,如果用户在航次框中输入数字 3,我希望能够为其下方的完整表格创建 3 个“副本”。

这是可以在 pdf 中使用 Javascript 完成的事情吗?我的想法是,它应该是可能的,但我在 adobe 论坛上找不到任何指示如何实现的内容。

最佳答案

您可以使用 JavaScript (Acrobat DC SDK) 复制 PDF 中的表单字段,如下所示(示例显示在每个页面上创建一个按钮):

var aPage = this.getPageBox();
var w = 45; // Width of each button
var h = 12 // Height of each button
var nNavi = 4; // Number of buttons to be placed
var g = 6; // Gap between buttons
var totalWidth = nNavi * w + (nNavi - 1) * g; // total width of navi bar

var widthPage = aPage[2] - aPage[0];

// Horizontal offset to center navi bar
var hoffset = (widthPage - totalWidth) / 2;
var voffset = 12; // vertical offset from bottom

for (var nPage = 0; nPage < this.numPages; nPage++) {
// Create the fields

var pp = this.addField("PrevPage", "button", nPage,
[ hoffset, voffset, hoffset + w, voffset + h ] );
pp.buttonSetCaption(pp.name);
pp.fillColor=color.ltGray;
pp.setAction("MouseUp", "this.pageNum--");

var np = this.addField("NextPage", "button", nPage,
[ hoffset + w + g, voffset, hoffset + 2*w + g, voffset + h ] );
np.buttonSetCaption(np.name);
np.fillColor=color.ltGray;
np.setAction("MouseUp", "this.pageNum++");

var pv = this.addField("PrevView", "button", nPage,
[ hoffset + 2*w + 2*g, voffset, hoffset + 3*w + 2*g, voffset + h ] );

pv.buttonSetCaption(pv.name);
pv.fillColor=color.ltGray;
pv.setAction("MouseUp", "app.goBack()");

var nv = this.addField("NextView", "button", nPage,
[ hoffset + 3*w + 3*g, voffset, hoffset + 4*w + 3*g, voffset + h ] );

nv.buttonSetCaption(nv.name);
nv.fillColor=color.ltGray;
nv.setAction("MouseUp", "app.goForward()");
}

[Source ]

documentation还注意到以下几点:

Multiple customized forms within a form based on user input

Subforms may also be subject to conditions. For example, form fields for dependent children would become visible if the user checks a box indicating that there are dependent children. In addition, XFA allows multiple form fields with the same name and multiple copies of the same form.

This page lists XFA specific methods您可能会发现这对您有用。

关于javascript - pdf 中的重复字段 - Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56488667/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com