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

时间:2014-11-18 23:05:49

标签: javascript adobe acrobat

我有一个工作的自定义动态图章,其中包含多个输入字段,提示用户。我现在想要尝试做的是以某种方式将一个表单文本字段放到实际渲染后的标记上。例如,如果有人最初在除分类帐代码之外的所有内容中加盖标记(因为他们当时不知道它们),然后将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;
    }    
  }
}

2 个答案:

答案 0 :(得分:1)

印章盖章后,不再可以修改(可以在页面上移动它,但这就是全部)。

因此,如果您“希望将图章变成表格”,则必须立即从表格开始。换句话说,为什么不直接放置用户可以在文档上填写的表单字段?

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

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

答案 1 :(得分:0)

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

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

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

Acrobat(或Reader)将检测到邮票的外观不再存在,因此它将基本上重新印记邮票并重新运行您的代码。