Search code examples
javascriptacrobatinputbox

Adobe Acrobat Action Wizard and Javascript


I'm using the Action Wizard tool in Adobe Acrobat Pro DC. I want to use "execute Javascript" to apply a watermark to the center of the PDF page as well as a persons name to the sides and the top. I successfully did this and here is the code.

var cMyText = "This PDF has been created for exclusive use for Max Power.";

this.addWatermarkFromText({
    cText: cMyText,
    nFontSize:9,
    nHorizAlign:app.constants.align.center,
    nVertAlign:app.constants.align.top,
    nVertValue:-10,
    nOpacity: 0.8,
});

this.addWatermarkFromText({
    cText: cMyText,
    nFontSize: 9,
    nRotation: 90,
    nHorizAlign: app.constants.align.left,
    nHorizValue: 10,
    nVertAlign: app.constants.align.center,
    nOpacity: 0.8,
});

this.addWatermarkFromText({
    cText: cMyText,
    nFontSize:9,
    nRotation:-90,
    nHorizAlign:app.constants.align.right,
    nHorizValue:-10,
    nVertAlign:app.constants.align.center,
    nOpacity: 0.8,
});

this.addWatermarkFromText({
    cText: "DRAFT COPY",
    nTextAlign:app.constants.align.center,
    cFont: "Helvetica-Bold",
    nFontSize:80,
    aColor: ["RGB", 0, 0, 1],
    nRotation:45,
    nOpacity: 0.2,
});

Now, here's my issue. The line...

"This PDF has been created for exclusive use for Max Power.";

will change each time I run the action. I don't want to risk having the user mess up the JavaScript by editing it directly in the code. I want to have an input box that will prompt the user to edit this line before the action is executed. Is this possible? Please help! Thanks.


Solution

  • Thanks! The below code did the trick!

    var dialogTitle = "Please Complete";
    
    var string1 = "This PDF has been created for exclusive use for";
    var defaultAnswer = "";
    
    var string2 = app.response("Add PDF recipients NAME or COMPANY",
    dialogTitle, defaultAnswer);
    
    var string3 = app.response("Add PDF recipients ADDRESS",
    dialogTitle, defaultAnswer);
    
    var cMyText = string1 +"\n"+ string2 +" "+ string3;
    var string4 = string2 +"\n"+ string3;
    
    this.addWatermarkFromText({
        cText: cMyText,
        nFontSize:9,
        nHorizAlign:app.constants.align.center,
        nVertAlign:app.constants.align.top,
        nVertValue:-10,
        nOpacity: 0.8,
    });
    
    this.addWatermarkFromText({
        cText: cMyText,
        nFontSize:9,
        nRotation:90,
        nHorizAlign:app.constants.align.left,
        nHorizValue:10,
        nVertAlign:app.constants.align.center,
        nOpacity: 0.8,
    });
    
    this.addWatermarkFromText({
        cText: cMyText,
        nFontSize:9,
        nRotation:-90,
        nHorizAlign:app.constants.align.right,
        nHorizValue:-10,
        nVertAlign:app.constants.align.center,
        nOpacity: 0.8,
    });
    
    this.addWatermarkFromText({
        cText: string4,
        nTextAlign:app.constants.align.center,
        cFont: "Helvetica-Bold",
        nFontSize:36,
        aColor: ["RGB", 0, 0, 1],
        nRotation:45,
        nOpacity: 0.2,
        bOnTop:false,
    });