default_noob_network
default_noob_network

Reputation: 1315

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

I have a working custom dynamic stamp with multiple input fields that the user is prompted. What I want to try to do now is somehow get a form text field onto the stamp AFTER it is actually rendered. For instance, if someone initially stamps in everything except for the ledger codes (because they don't know them at the time) and then sends the PDF off to someone who DOES know the ledger codes, I want to have the ability for those ledger codes to be added in like they were editable form fields and not have to use an additional stamp.

So really, after the stamp is "stamped" I don't really want it to be a stamp anymore... I want it to now be a form (I think...)

Here is the working code for the stamp (minus the "approve" field)

    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;
    }    
  }
}

Upvotes: 0

Views: 2292

Answers (2)

joelgeraci
joelgeraci

Reputation: 4907

You actually can get a dynamic stamp to re-render. All you need to do is use JavaScript to get the annotation object that corresponds to the stamp in question, get it's properties object, delete the APCosObj property and then set the properties to the modified properties object. As long as the custom stamp is still installed in Acrobat, the dialog will pop up and allow a user to enter the data. Unfortunately, the existing data on the stamp can't be accessed directly so you'd need to provide a mechanism for storing it. All annotations get a unique "name" property when created so you can use the name to connect the stored data to the annotation.

Assuming your annotation is the first one on the first page, you code might look like this...

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

Acrobat (or Reader) will detect that the appearance for the stamp doesn't exist anymore so it will essentially restamp the stamp and rerun your code.

Upvotes: 1

Max Wyss
Max Wyss

Reputation: 3605

Once a stamp is stamped, it no longer can be modified (it may be possible to move it around on the page, but that's about all).

So, if you "want a stamp turn into a form", you would have to start with a form right away. In other words, why don't you just place form fields your users can fill out on the document?

You would use the addField() method to add the fields.

If your document needs to be supported in Reader, you may either insist on using Reader XI or newer, or you will have to add Extended Rights.

Upvotes: 1

Related Questions