2

如何在 Acrobat 中将多个字段链接在一起,以便用户可以在当前字段已满时继续写入下一个字段?理想情况下,如果粘贴的字符串对于该字段来说太长,那么将数据粘贴到一个字段中也会继续粘贴到下一个字段中。

在这种特定情况下,这些字段用于输入 4 位一组的 IBAN 号码,因为这是 PDF 表单字段下方的纸质表单上使用的布局: IBAN 字段

4

1 回答 1

0

虽然它并不完美,但您可以将以下函数用作文档范围的函数。唯一的问题是,在粘贴跨多个字段的文本时,光标没有正确移动到正确的字段。

Acrobat 9:高级 > 文档处理 > 文档 JavaScript
Acrobat 10:工具 > JavaScript > 文档 JavaScript

function tab_chain(prev_field_name, next_fields) {
    // Move to next field if the current keystroke
    // fills the field. Move to the previous field
    // if the current keystroke empties the field.

    // Pasted data that is too long for the current
    // will be continued into the fields listed in
    // the next_fields array.

    var rest, prev, next, i;
    event.change = event.change.toUpperCase();
    rest = event.changeEx.toUpperCase();
    var merged = AFMergeChange(event);
    //console.println("Name: '" + event.target.name + "'");
    //console.println("Merged: '" + merged + "'");

    if (merged.length === event.target.charLimit) {
        //console.println("Limit: " + event.target.charLimit);
        i = 0;
        prev = event.target;
        next = getField(next_fields[i++]);
        rest = rest.substr(event.change.length);
        while (next !== null && rest.length > 0) {
            //console.println("Rest: " + rest);
            merged = rest.substr(0, next.charLimit);
            rest = rest.substr(merged.length);
            next.value = merged;
            prev = next;
            next = getField(next_fields[i++]);
        }
        // Update focus if previous pasted field is full.
        if (next !== null && merged.length === prev.charLimit) {
            next.setFocus();
        }
    }
    else if (merged.length === 0) {
        getField(prev_field_name).setFocus();
    }
}

然后,在Properties > Format下将此函数作为自定义击键脚本调用。作为第一个参数,您传递链中的前一个字段(或字段本身,如果它是第一个)。作为第二个参数,您传递链中以下字段的列表。例如,如果您的字段称为 IBAN1、IBAN2、...、IBAN6:

IBAN1tab_chain("IBAN1", ["IBAN2", "IBAN3", "IBAN4", "IBAN5", "IBAN6"]);
脚本:IBAN2 脚本:IBAN3tab_chain("IBAN1", ["IBAN3", "IBAN4", "IBAN5", "IBAN6"]);
脚本:tab_chain("IBAN2", ["IBAN4", "IBAN5", "IBAN6"]);
等。

于 2014-07-29T12:20:51.957 回答