允许在标记自定义动态图章后编辑表单字段

Allow editing of form field AFTER a custom dynamic stamp is stamped

本文关键字:编辑 表单 字段 动态 自定义      更新时间:2023-09-26

>我有一个有效的自定义动态图章,其中包含多个提示用户的输入字段。我现在想尝试做的是在实际渲染后以某种方式将表单文本字段放在邮票上。例如,如果有人最初在除分类账代码之外的所有内容上加盖章(因为他们当时不知道它们),然后将 PDF 发送给确实知道分类账代码的人,我希望能够将这些分类账代码添加进来,就像它们是可编辑的表单字段一样,而不必使用额外的印章。

所以真的,邮票

被"盖章"之后,我真的不希望它成为邮票了......我希望它现在是一种形式(我认为...

这是邮票的工作代码(减去"批准"字段)

    var dialog = {
    VendorNum: "",
    Date: "",
    ProjNumRow1: "",
    ProjNumRow2: "",
    ProjNumRow3: "",
    ProjNumRow4: "",
    GLCodeRow1: "",
    GLCodeRow2: "",
    GLCodeRow3: "",
    GLCodeRow4: "",
    AmountRow1: "",
    AmountRow2: "",
    AmountRow3: "",
    AmountRow4: "",
    Approval: "",
    commit:function (dialog) { // called when OK pressed 
        var results = dialog.store();
        this.VendorNum = results["txt1"];
        this.Date = results["txt2"];
        this.ProjNumRow1 = results["txt3"];
        this.ProjNumRow2 = results["txt4"];
        this.ProjNumRow3 = results["txt5"];
        this.ProjNumRow4 = results["txt6"];
        this.GLCodeRow1 = results["txt7"];
        this.GLCodeRow2 = results["txt8"];
        this.GLCodeRow3 = results["txt9"];
        this.GLCodeRow4 = results["txtA"];
        this.AmountRow1 = results["txtB"];
        this.AmountRow2 = results["txtC"];
        this.AmountRow3 = results["txtD"];
        this.AmountRow4 = results["txtE"];
        this.Approval = results["Approval"];
    },      
    description:
    {       
        name: "Accounts Payable",    // Dialog box title
        width: 400,
        height: 400,
        elements:
        [
            {
                type: "view",
                align_children: "align_left",
                elements:
                [
                    {
                        name: "TopGapPlaceholder",
                        type: "gap",
                        height: 20,
                    },
                ]
            },
            {
                type: "view",
                alignment: "align_center",
                elements:
                [
                    {       
                        name: "ACCOUNTS PAYABLE",
                        type: "static_text",
                        alignment: "align_center",
                        width: 120,
                    },                                
                ]
            },
            {
                type: "view",
                align_children: "align_left",
                elements:
                [
                    {
                        name: "TopGapPlaceholder",
                        type: "gap",
                        height: 20,
                    },
                ]
            },
            {
                type: "cluster",
                elements:
                [
                    {
                        type: "view",
                        width: 70,
                        elements:
                        [
                            {
                                type: "view",
                                align_children: "align_row",
                                elements:
                                [
                                    {       
                                        name: "Vendor #: ",
                                        type: "static_text",
                                        alignment: "align_right",
                                        width: 80,
                                    },      
                                    {       
                                        item_id: "txt1", 
                                        type: "edit_text",
                                        multiline: false,
                                        width: 100,
                                        height: 20
                                    },                                 
                                ]                            
                            },
                            {
                                type: "view",
                                align_children: "align_row",
                                elements:
                                [   
                                    {       
                                        name: "Date: ",
                                        type: "static_text",
                                        alignment: "align_right",
                                        width: 80,
                                    },      
                                    {       
                                        item_id: "txt2", 
                                        type: "edit_text",
                                        multiline: false,
                                        width: 100,
                                        height: 20
                                    },
                                ]  
                            }
                        ]
                    }
                ]
            },
            {
                type: "view",
                align_children: "align_left",
                elements:
                [
                    {
                        name: "AboveProjectsGapPlaceholder",
                        type: "gap",
                        height: 30,
                    },
                ]
            },
            {
                type: "view",
                align_children: "align_row",                
                elements:
                [   
                    {
                        type: "view",
                        elements:
                        [
                            {
                                type: "view",
                                align_children: "align_left",
                                elements:
                                [
                                    {
                                        name: "RowGapPlaceholder",
                                        type: "gap",
                                        height: 20,
                                    },
                                    {       
                                        name: "Row 1: ",
                                        type: "static_text",
                                        height: 20,
                                    },
                                    {       
                                        name: "Row 2: ",
                                        type: "static_text",
                                        height: 20,
                                    }, 
                                    {       
                                        name: "Row 3: ",
                                        type: "static_text",
                                        height: 20,
                                    }, 
                                    {       
                                        name: "Row 4: ",
                                        type: "static_text",
                                        height: 20,
                                    },                                
                                ]                            
                            },
                        ]
                    },                 
                    {                      
                        type: "cluster",                        
                        elements:
                        [
                            {
                                type: "view",
                                align_children: "align_center",
                                elements:
                                [
                                    {       
                                        name: "Project #",
                                        type: "static_text",
                                    },
                                ]
                            },
                            {
                                type: "view",
                                align_children: "align_left",
                                elements:
                                [                    
                                    // PROJECT NUMBERS COLUMN
                                    {       
                                            item_id: "txt3", 
                                            type: "edit_text",
                                            //alignment: "align_row",
                                            multiline: false,
                                            width: 100,
                                            height: 20
                                    },     
                                    {       
                                            item_id: "txt4", 
                                            type: "edit_text",
                                            //alignment: "align_row",
                                            multiline: false,
                                            width: 100,
                                            height: 20
                                    },      
                                    {       
                                            item_id: "txt5", 
                                            type: "edit_text",
                                            //alignment: "align_row",
                                            multiline: false,
                                            width: 100,
                                            height: 20
                                    },
                                    {       
                                            item_id: "txt6", 
                                            type: "edit_text",
                                            //alignment: "align_row",
                                            multiline: false,
                                            width: 100,
                                            height: 20
                                    },
                                ]
                            }
                        ]
                    },
                    {
                        type: "cluster",                        
                        elements:
                        [
                            {
                                type: "view",
                                align_children: "align_center",
                                elements:
                                [
                                    {       
                                        name: "General Ledger Code",
                                        type: "static_text",
                                    },
                                ]
                            },
                            {
                                type: "view",
                                align_children: "align_left",
                                elements:
                                [                    
                                    //  GL CODES COLUMN                                        
                                    {       
                                            item_id: "txt7", 
                                            type: "edit_text",
                                            //alignment: "align_row",
                                            multiline: false,
                                            width: 100,
                                            height: 20
                                    },     
                                    {       
                                            item_id: "txt8", 
                                            type: "edit_text",
                                            //alignment: "align_row",
                                            multiline: false,
                                            width: 100,
                                            height: 20
                                    },      
                                    {       
                                            item_id: "txt9", 
                                            type: "edit_text",
                                            //alignment: "align_row",
                                            multiline: false,
                                            width: 100,
                                            height: 20
                                    },
                                    {       
                                            item_id: "txtA", 
                                            type: "edit_text",
                                            //alignment: "align_row",
                                            multiline: false,
                                            width: 100,
                                            height: 20
                                    },
                                ]
                            }
                        ]
                    },
                    {
                        type: "cluster",                        
                        elements:
                        [
                            {
                                type: "view",
                                align_children: "align_center",
                                elements:
                                [
                                    {       
                                        name: "Amount",
                                        type: "static_text",
                                    },
                                ]
                            },
                            {
                                type: "view",
                                align_children: "align_left",
                                elements:
                                [                    
                                    // AMOUNT COLUMN
                                    {       
                                            item_id: "txtB", 
                                            type: "edit_text",
                                            //alignment: "align_row",
                                            multiline: false,
                                            width: 100,
                                            height: 20
                                    },     
                                    {       
                                            item_id: "txtC", 
                                            type: "edit_text",
                                            //alignment: "align_row",
                                            multiline: false,
                                            width: 100,
                                            height: 20
                                    },      
                                    {       
                                            item_id: "txtD", 
                                            type: "edit_text",
                                            //alignment: "align_row",
                                            multiline: false,
                                            width: 100,
                                            height: 20
                                    },
                                    {       
                                            item_id: "txtE", 
                                            type: "edit_text",
                                            //alignment: "align_row",
                                            multiline: false,
                                            width: 100,
                                            height: 20
                                    },
                                ]
                            }
                        ]
                    },
                ]
            },
            {
                type: "view",
                align_children: "align_left",
                elements:
                [
                    {
                        name: "ButtonGapPlaceholder",
                        type: "gap",
                        height: 50,
                    },
                ]
            },
            {
                type: "cluster",
                align_children: "align_right",
                elements:
                [
                    {
                        type: "view",
                        align_children: "align_row",
                        elements:
                        [
                            // BUTTON GROUP
                            {       
                                    type: "ok_cancel",
                                    ok_name: "Ok",
                                    cancel_name: "Cancel"
                            },      
                        ]
                    }
                ]
            }
        ]          
    }       
}; 
if(event.source && event.source.forReal && (event.source.stampName == "#8ykdtJ56pcQrQ7Sxn1-99A"))
{
  if ("ok" == app.execDialog(dialog))
  {
    console.println(dialog.VendorNum);
    console.println(dialog.Date);
    console.println(dialog.ProjNumRow1);
    console.println(dialog.ProjNumRow2);
    console.println(dialog.ProjNumRow3);
    console.println(dialog.ProjNumRow4);
    console.println(dialog.GLCodeRow1);
    console.println(dialog.GLCodeRow2);
    console.println(dialog.GLCodeRow3);
    console.println(dialog.GLCodeRow4);
    console.println(dialog.AmountRow1);
    console.println(dialog.AmountRow2);
    console.println(dialog.AmountRow3);
    console.println(dialog.AmountRow4);
    if (!dialog.VendorNum) {
        this.getField("VendorNum").value = "";
    } else {
        this.getField("VendorNum").value = dialog.VendorNum;
    }
    if (!dialog.Date) {
        this.getField("Date").value = "";
    } else {
        this.getField("Date").value = dialog.Date;
    }
    if (!dialog.ProjNumRow1) {
        this.getField("ProjNumRow1").value = "";
    } else {
        this.getField("ProjNumRow1").value = dialog.ProjNumRow1;
    }
    if (!dialog.ProjNumRow2) {
        this.getField("ProjNumRow2").value = "";
    } else {
        this.getField("ProjNumRow2").value = dialog.ProjNumRow2;
    }
    if (!dialog.ProjNumRow3) {
        this.getField("ProjNumRow3").value = "";
    } else {
        this.getField("ProjNumRow3").value = dialog.ProjNumRow3;
    }
    if (!dialog.ProjNumRow4) {
        this.getField("ProjNumRow4").value = "";
    } else {
        this.getField("ProjNumRow4").value = dialog.ProjNumRow4;
    }
    if (!dialog.GLCodeRow1) {
        this.getField("GLCodeRow1").value = "";
    } else {
        this.getField("GLCodeRow1").value = dialog.GLCodeRow1;
    }
    if (!dialog.GLCodeRow2) {
        this.getField("GLCodeRow2").value = "";
    } else {
        this.getField("GLCodeRow2").value = dialog.GLCodeRow2;
    }
    if (!dialog.GLCodeRow3) {
        this.getField("GLCodeRow3").value = "";
    } else {
        this.getField("GLCodeRow3").value = dialog.GLCodeRow3;
    }
    if (!dialog.GLCodeRow4) {
        this.getField("GLCodeRow4").value = "";
    } else {
        this.getField("GLCodeRow4").value = dialog.GLCodeRow4;
    }
    if (!dialog.AmountRow1) {
        this.getField("AmountRow1").value = "";
    } else {
        this.getField("AmountRow1").value = dialog.AmountRow1;
    }
    if (!dialog.AmountRow2) {
        this.getField("AmountRow2").value = "";
    } else {
        this.getField("AmountRow2").value = dialog.AmountRow2;
    }
    if (!dialog.AmountRow3) {
        this.getField("AmountRow3").value = "";
    } else {
        this.getField("AmountRow3").value = dialog.AmountRow3;
    }
    if (!dialog.AmountRow4) {
        this.getField("AmountRow4").value = "";
    } else {
        this.getField("AmountRow4").value = dialog.AmountRow4;
    }
    if (!dialog.Approval) {
        this.getField("Approval").value = "";
    } else {
        this.getField("Approval").value = dialog.Approval;
    }    
  }
}

一旦邮票被盖章,就不能再修改它了(也许可以在页面上移动它,但仅此而已)。

因此,如果您"希望将邮票变成表格",则必须立即从表格开始。换句话说,您为什么不只在文档中放置用户可以填写的表单字段?

您可以使用 addField() 方法来添加字段。

如果您的文档需要在 Reader 中受支持,您可以坚持使用 Reader XI 或更高版本,或者您必须添加扩展权限。

您实际上可以获得一个动态标记来重新渲染。您需要做的就是使用 JavaScript 获取与相关图章对应的注释对象,获取其属性对象,删除 APCosObj 属性,然后将属性设置为修改的属性对象。只要自定义图章仍安装在 Acrobat 中,就会弹出对话框并允许用户输入数据。不幸的是,无法直接访问图章上的现有数据,因此您需要提供一种存储它的机制。所有批注在创建时都会获得唯一的"name"属性,以便您可以使用该名称将存储的数据连接到批注。

假设您的注释是第一页上的第一个注释,您的代码可能如下所示...

annot = this.getAnnots()[0];
props = annot.getProps();
delete props.APCosObj;
annot.setProps(props);

Acrobat (或 Reader) 将检测到图章的外观不再存在,因此它实质上会重新标记图章并重新运行您的代码。