Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

getPageNthWord returning [object Doc] when used in a text field custom calculation

New Here ,
Dec 11, 2020 Dec 11, 2020

Hello

 

Using Acrobat DC Pro.

 

When I try to the use the function this.getPageNthWord() or doc.getPageNthWord() and convert it to a string, I get the [object Doc] instead of a word. I can use the function this.getPageNthWord() by intelf on the same document on the console command and it comes up with the first word in the document, but not when I use the function in the custom calculation of a text field.

Bit of context

I have a working custom stamp that brings up an execDialog box for the user to enter stamp data into when the stamp is placed. I would like the stamp dialogbox text fields to be filled in with data from text on the document when the stamp is applied.

TOPICS
JavaScript
4.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Dec 14, 2020 Dec 14, 2020

Yes, in the context of a dynamic stamp event.source.source returns the document to which the stamp is being applied. And I tried it with event.source.source.pageNum and it worked fine, by the way.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2020 Dec 11, 2020

Post your full code, please.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 14, 2020 Dec 14, 2020
The following code is used in the custom calculation script of the txt1 text field in the InvoiceStamp1 pdf. The lines of problem code are maked with the comment "Problem code". If I ommit the problem code lines the stamp works properly. After reading ls_rbls comment and the reference doc they sent, I think my problem may be that I don't know how to (or if its possible to) use the .getPageNthWord() function inside of a stamp. I did a little bit of testing and I could get the getPageNthWord function to return words from the stamp pdf, but cannot get words from the page of the document the stamp is being applied to. Any insight and help is much appreciated.
 
// Start code
// Tested on Adobe DC Pro version 2020.013.20066
// when any stamp in the Stamp File is being placed on the document and when stamp has this name
if (event.source.forReal && (event.source.stampName == "#InvoiceStamp1"))
{
    // trims beginning and end of string. Gets rid of leading and trailing; spaces, line feed, caridge returns, horizontal tabs.
    function trim (str) {
        return str.replace (/(^[\s\n\r\t\x0B]+)|([\s\n\r\t\x0B]+$)/g'');
    };
    var JSADMDlg1 = {
        result: "cancel",
        DoDialog: function() {
            return app.execDialog(this);
        },
        vendor: "vend",
        invoice: "inv#",
        invoicedatem: "idtm",
        invoicedated: "idtd",
        invoicedatey: "idty",
        dateofrecordm: "dorm",
        dateofrecordy: "dory",
        invoicedescription: "txt5",
        company: "txt6",
        project: "txt7",
        job: "txt8",
        costcode: "txt9",
        amount: "tzt1",
        glcode: "tzt2",
        duedatem: "ddtm",
        duedated: "ddtd",
        duedatey: "ddty",
        // method that runs when the dialog box is created
        initialize: function(dialog) {
            var dlgInit = {
                "vend": this.vendor,
                "inv#": this.invoice,
                "idtm": this.invoicedatem,
                "idtd": this.invoicedated,
                "idty": this.invoicedatey,
                "dorm": this.dateofrecordm,
                "dory": this.dateofrecordy,
                "txt5": this.invoicedescription,
                "txt6": this.company,
                "txt7": this.project,
                "txt8": this.job,
                "txt9": this.costcode,
                "tzt1": this.amount,
                "tzt2": this.glcode,
                "ddtm": this.duedatem,
                "ddtd": this.duedated,
                "ddty": this.duedatey,
            };
            dialog.load(dlgInit);
        },
        //validate dialog box. validation occurs after pressing the OK button
        validate: function(dialog) {
            var oVslt = dialog.store();
            if (trim(oVslt["vend"]).length > 7) {
                app.alert("Vendor Code\nMust be 7 or less characters long");
                return false;
            };
            var tidtm = trim(oVslt["idtm"]);
            var tidtd = trim(oVslt["idtd"]);
            var tidty = trim(oVslt["idty"]);
            if(tidtm != ""){
                if (tidtm < 1 || tidtm > 13 || isNaN(tidtm)) {
                    app.alert("Invoice Date (Month)\nMust be a number between 1 and 12 or left blank");
                    return false;
                };
            };
            if(tidtd != ""){
                if (tidtd < 1 || tidtd > 31 || isNaN(tidtd)) {
                    app.alert("Invoice Date (Day)\nMust be a number between 1 and 31 or left blank");
                    return false;
                };
            };
            if(tidty != ""){
                if (tidty < 1 || tidty > 99 || isNaN(tidty)) {
                    app.alert("Invoice Date (Year)\nMust be a number between 1 and 99 or left blank");
                    return false;
                };
            };
            if (tidtm.length == 1) {
                tidtm = "0" + tidtm;
            };
            if (tidtd.length == 1) {
                tidtd = "0" + tidtd;
            };
            if (tidty.length == 1) {
                tidty = "0" + tidty;
            };
            if(tidtm != "" && tidtd != "" && tidty != ""){
                if (util.scand("mm-dd-yy"tidtm + "-" + tidtd + "-" + tidty) == null) {
                    app.alert("Invoice Date\nThe enetered date is not a valid date.");
                    return false;
                };
            };
            if (trim(oVslt["inv#"]).length > 8) {
                app.alert("Invoice #\nMust be 8 or less characters long");
                return false;
            };
            if(trim(oVslt["dorm"]) != ""){
                if (trim(oVslt["dorm"]) < 1 || trim(oVslt["dorm"]) > 13 || isNaN(trim(oVslt["dorm"]))) {
                    app.alert("Date of Record (Month)\nMust be a number between 1 and 12 or left blank");
                    return false;

 

                };
            };
            if(trim(oVslt["dory"]) != ""){
                if (trim(oVslt["dory"]) < 0 || trim(oVslt["dory"]) > 99 || isNaN(trim(oVslt["dory"]))) {
                    app.alert("Date of Record (Year)\nMust be a number between 00 and 99 or left blank");
                    return false;
                };
            };
            if(trim(oVslt["txt6"]) != ""){
                if (trim(oVslt["txt6"]) < 1 || trim(oVslt["txt6"]) > 9999 || isNaN(trim(oVslt["txt6"]))) {
                    app.alert("Company #\nMust be a number between 1 and 9999 or left blank");
                    return false;
                };
            };
            if(trim(oVslt["txt7"]) != ""){
                if (trim(oVslt["txt7"]) < 1 || trim(oVslt["txt7"]) > 99999 || isNaN(trim(oVslt["txt7"]))) {
                    app.alert("Project #\nMust be a number between 1 and 99999 or left blank");
                    return false;
                };
            };
            if (trim(oVslt["txt8"]).length > 5) {
                app.alert("Job #\nMust be 5 or less characters long");
                return false;
            };
            if(trim(oVslt["txt9"]) != ""){
                if (trim(oVslt["txt9"]) < 1 || trim(oVslt["txt9"]) > 99999 || isNaN(trim(oVslt["txt9"]))) {
                    app.alert("Cost Code\nMust be a number between 1 and 99999 or left blank");
                    return false;
                };
            };
            if (isNaN(trim(oVslt["tzt1"]))) {
                app.alert("Total Amount\nMust be a number");
                return false;
            };
            var tddtm = trim(oVslt["ddtm"]);
            var tddtd = trim(oVslt["ddtd"]);
            var tddty = trim(oVslt["ddty"]);
            if(tddtm != ""){
                if (tddtm < 1 || tddtm > 13 || isNaN(tddtm)) {
                    app.alert("Due Date (Month)\nMust be a number between 1 and 12 or left blank");
                    return false;
                };
            };
            if(tddtd != ""){
                if (tddtd < 1 || tddtd > 31 || isNaN(tddtd)) {
                    app.alert("Due Date (Day)\nMust be a number between 1 and 31 or left blank");
                    return false;
                };
            };
            if(tddty != ""){
                if (tddty < 1 || tddty > 99 || isNaN(tddty)) {
                    app.alert("Due Date (Year)\nMust be a number between 1 and 99 or left blank");
                    return false;
                };
            };
            if (tddtm.length == 1) {
                tddtm = "0" + tddtm;
            };
            if (tddtd.length == 1) {
                tddtd = "0" + tddtd;
            };
            if (tddty.length == 1) {
                tddty = "0" + tddty;
            };
            if(tddtm != "" && tddtd != "" && tddty != ""){
                if(util.scand("mm-dd-yy"tddtm + "-" + tddtd + "-" + tddty) == null){
                    app.alert("Due Date\nThe enetered date is not a valid date.");
                    return false;
                };
            };
            return true;
        },
        //method that is called when OK button is selected
        commit: function(dialog) {
            var oRslt = dialog.store();
            this.vendor = trim(oRslt["vend"]).toUpperCase();
            this.invoice = trim(oRslt["inv#"]).toUpperCase();
            this.invoicedatem = trim(oRslt["idtm"]).toUpperCase();
            this.invoicedated = trim(oRslt["idtd"]).toUpperCase();
            this.invoicedatey = trim(oRslt["idty"]).toUpperCase();
            this.dateofrecordm = trim(oRslt["dorm"]).toUpperCase();
            this.dateofrecordy = trim(oRslt["dory"]).toUpperCase();
            this.invoicedescription = trim(oRslt["txt5"]).toUpperCase();
            this.company = trim(oRslt["txt6"]).toUpperCase();
            this.project = trim(oRslt["txt7"]).toUpperCase();
            this.job = trim(oRslt["txt8"]).toUpperCase();
            this.costcode = trim(oRslt["txt9"]).toUpperCase();
            this.amount = trim(oRslt["tzt1"]).toUpperCase();
            this.glcode = trim(oRslt["tzt2"]).toUpperCase();
            this.duedatem = trim(oRslt["ddtm"]).toUpperCase();
            this.duedated = trim(oRslt["ddtd"]).toUpperCase();
            this.duedatey = trim(oRslt["ddty"]).toUpperCase();
        },
        description: {
            name: "JSADM Dialog",
            elements: [
                {
                type: "view",
                elements: [
                    {
                        type: "static_text",
                        item_id: "hed1",
                        name: "Press \"Tab\" or \"Shift + Tab\" to easily move between fields"

 

                    },
                    {
                    type: "view",
                    elements: [
                        {
                            type: "view",
                            align_children: "align_row",
                            elements: [
                                {
                                    type: "static_text",
                                    item_id: "sta1",
                                    name: "Vendor Code",
                                    char_width: 10,
                                },
                                {
                                    type: "edit_text",
                                    item_id: "vend",
                                    variable_Name: "vendor",
                                    char_width: 7,
                                }
                            ]
                        },
                        {
                            type: "view",
                            align_children: "align_row",
                            elements: [
                                {
                                    type: "static_text",
                                    item_id: "sta2",
                                    name: "Invoice #",
                                    char_width: 10,
                                },
                                {
                                    type: "edit_text",
                                    item_id: "inv#",
                                    variable_Name: "invoice",
                                    char_width: 8,
                                }
                            ]
                        },
                        {
                            type: "cluster",
                            align_children: "align_row",
                            elements: [
                                {
                                    type: "static_text",
                                    item_id: "sta3",
                                    name: "Invoice Date",
                                    char_width: 8,
                                },
                                {
                                    type: "view",
                                    align_children: "align_fill",
                                    elements: [
                                        {
                                            type: "static_text",
                                            item_id: "st3m",
                                            name: "Month",
                                        },
                                        {
                                            type: "edit_text",
                                            item_id: "idtm",
                                            variable_Name: "invoicedatem",
                                        }
                                    ]
                                },
                                {
                                    type: "view",
                                    align_children: "align_fill",
                                    elements: [
                                        {
                                            type: "static_text",
                                            item_id: "st3d",
                                            name: "Day",
                                        },
                                        {
                                            type: "edit_text",
                                            item_id: "idtd",
                                            variable_Name: "invoicedated",
                                        }
                                    ]
                                },
                                {
                                    type: "view",
                                    align_children: "align_fill",
                                    elements: [
                                        {
                                            type: "static_text",
                                            item_id: "st3y",
                                            name: "Year",
                                        },
                                        {
                                            type: "edit_text",
                                            item_id: "idty",
                                            variable_Name: "invoicedatey",
                                        }
                                    ]
                                },
                            ]
                        },
                        {
                            type: "cluster",
                            align_children: "align_row",
                            elements: [
                                {
                                    type: "static_text",
                                    item_id: "sta4",
                                    name: "Date of Record",
                                    char_width: 7,
                                },
                                {
                                    type: "view",
                                    align_children: "align_fill",
                                    elements: [
                                        {
                                            type: "static_text",
                                            item_id: "st4m",
                                            name: "Month",
                                        },
                                        {
                                            type: "edit_text",
                                            item_id: "dorm",
                                            variable_Name: "dateofrecordm",
                                        }
                                    ]
                                },
                                {
                                    type: "view",
                                    align_children: "align_fill",
                                    elements: [
                                        {
                                            type: "static_text",
                                            item_id: "st4y",
                                            name: "Year",
                                        },
                                        {
                                            type: "edit_text",
                                            item_id: "dory",
                                            variable_Name: "dateofrecordy",
                                        }
                                    ]
                                },
                            ]
                        },
                        {
                            type: "view",
                            align_children: "align_row",
                            elements: [
                                {
                                    type: "static_text",
                                    item_id: "sta5",
                                    name: "Description",
                                    char_width: 10,
                                },
                                {
                                    type: "edit_text",
                                    item_id: "txt5",
                                    variable_Name: "invoicedescription",
                                    char_width: 10,
                                }
                            ]
                        },
                        {
                            type: "view",
                            align_children: "align_row",
                            elements: [
                                {
                                    type: "static_text",
                                    item_id: "sta6",
                                    name: "Company #",
                                    char_width: 10,
                                },
                                {
                                    type: "edit_text",
                                    item_id: "txt6",
                                    variable_Name: "company",
                                    char_width: 4,
                                }
                            ]
                        },
                        {
                            type: "cluster",
                            elements: [
                                {
                                    type: "view",
                                    align_children: "align_row",
                                    elements: [
                                        {
                                            type: "static_text",
                                            item_id: "sta7",
                                            name: "Project #",
                                            char_width: 8,
                                        },
                                        {
                                            type: "edit_text",
                                            item_id: "txt7",
                                            variable_Name: "project",
                                            char_width: 5,
                                        }
                                    ]
                                },
                                {
                                    type: "view",
                                    align_children: "align_row",
                                    elements: [
                                        {
                                            type: "static_text",
                                            item_id: "sta8",
                                            name: "Job #",
                                            char_width: 8,
                                        },
                                        {
                                            type: "edit_text",
                                            item_id: "txt8",
                                            variable_Name: "job",
                                            char_width: 5,
                                        }
                                    ]
                                },
                                {
                                    type: "view",
                                    align_children: "align_row",
                                    elements: [
                                        {
                                            type: "static_text",
                                            item_id: "sta9",
                                            name: "Cost Code",
                                            char_width: 8,
                                        },
                                        {
                                            type: "edit_text",
                                            item_id: "txt9",
                                            variable_Name: "costcode",
                                            char_width: 5,
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            type: "view",
                            align_children: "align_row",
                            elements: [
                                {
                                    type: "static_text",
                                    item_id: "st10",
                                    name: "Total Amount",
                                    char_width: 10,
                                },
                                {
                                    type: "edit_text",
                                    item_id: "tzt1",
                                    variable_Name: "amount",
                                    char_width: 12,
                                }
                            ]
                        },
                        {
                            type: "view",
                            align_children: "align_row",
                            elements: [
                                {
                                    type: "static_text",
                                    item_id: "st11",
                                    name: "GL Code",
                                    char_width: 10,
                                },
                                {
                                    type: "edit_text",
                                    item_id: "tzt2",
                                    variable_Name: "glcode",
                                    char_width: 15,
                                }
                            ]
                        },
                        {
                            type: "cluster",
                            align_children: "align_row",
                            elements: [
                                {
                                    type: "static_text",
                                    item_id: "st12",
                                    name: "Due Date",
                                    char_width: 8,
                                },
                                {
                                    type: "view",
                                    align_children: "align_fill",
                                    elements: [
                                        {
                                            type: "static_text",
                                            item_id: "s13m",
                                            name: "Month",
                                        },
                                        {
                                            type: "edit_text",
                                            item_id: "ddtm",
                                            variable_Name: "duedatem",
                                        }
                                    ]
                                },
                                {
                                    type: "view",
                                    align_children: "align_fill",
                                    elements: [
                                        {
                                            type: "static_text",
                                            item_id: "s13d",
                                            name: "Day",
                                        },
                                        {
                                            type: "edit_text",
                                            item_id: "ddtd",
                                            variable_Name: "duedated",
                                        }
                                    ]
                                },
                                {
                                    type: "view",
                                    align_children: "align_fill",
                                    elements: [
                                        {
                                            type: "static_text",
                                            item_id: "s13y",
                                            name: "Year",
                                        },
                                        {
                                            type: "edit_text",
                                            item_id: "ddty",
                                            variable_Name: "duedatey",
                                        }
                                    ]
                                },
                            ]
                        },
                    ]
                    },
                    {
                        type: "ok_cancel",
                        alignment: "align_right",
                    },

 

                ]
            }, ]
        }
    };
// set initial values for dialog text fields
var test1 = event.target.doc.getPageNthWord(0,0); //Problem code
// var test1 = this.getPageNthWord(0,0); //Problem code
JSADMDlg1.vendor = toString(test1); //Problem code
// JSADMDlg1.vendor = "   ";
JSADMDlg1.invoice = "   ";
JSADMDlg1.invoicedatem = "   ";
JSADMDlg1.invoicedated = "   ";
JSADMDlg1.invoicedatey = "   ";
JSADMDlg1.dateofrecordm = "   ";
JSADMDlg1.dateofrecordy = "   ";
JSADMDlg1.invoicedescription = "   ";
JSADMDlg1.company = "   ";
JSADMDlg1.project = "   ";
JSADMDlg1.job = "   ";
JSADMDlg1.costcode = "   ";
JSADMDlg1.amount = "   ";
JSADMDlg1.glcode = "   ";
JSADMDlg1.duedatem = "   ";
JSADMDlg1.duedated = "   ";
JSADMDlg1.duedatey = "   ";
//set the stamp text field to equal the entered dialog text fields
if ("ok" == JSADMDlg1.DoDialog()) {
    this.getField("txt1").value = JSADMDlg1.vendor;
    this.getField("txt2").value = JSADMDlg1.invoice;
    if (JSADMDlg1.invoice.length < 11) {
        this.getField("txt2").textSize = 11;
        } else {
        this.getField("txt2").textSize = 0;
    };
    if (JSADMDlg1.invoicedatem == "" && JSADMDlg1.invoicedated == "" && JSADMDlg1.invoicedatey == "") {
        this.getField("txt3").value = "";
        } else if (JSADMDlg1.invoicedatem == "" || JSADMDlg1.invoicedated == "" || JSADMDlg1.invoicedatey == ""){
        this.getField("txt3").value = JSADMDlg1.invoicedatem + "/" + JSADMDlg1.invoicedated + "/" + JSADMDlg1.invoicedatey;
        } else {
            var tempidt = JSADMDlg1.invoicedatem + "-" + JSADMDlg1.invoicedated + "-" + JSADMDlg1.invoicedatey;
            var tempidt1 = util.scand("mm-dd-yy"tempidt);
            this.getField("txt3").value = util.printd("mm/dd/yy"tempidt1);
        };
    if (JSADMDlg1.dateofrecordm == "" && JSADMDlg1.dateofrecordy == "") {
        this.getField("txt4").value = "";
        } else if (JSADMDlg1.dateofrecordm == "" || JSADMDlg1.dateofrecordy == ""){
        this.getField("txt4").value = JSADMDlg1.dateofrecordm + "/" + JSADMDlg1.dateofrecordy;
        } else {
            var tempdrt = JSADMDlg1.dateofrecordm + "-" + JSADMDlg1.dateofrecordy;
            var tempdrt1 = util.scand("mm-yy"tempdrt);
            this.getField("txt4").value = util.printd("mm/yy"tempdrt1);
        };
    this.getField("txt5").value = JSADMDlg1.invoicedescription;
    if (JSADMDlg1.invoicedescription.length < 11) {
        this.getField("txt5").textSize = 11;
        } else {
        this.getField("txt5").textSize = 0;
    };
    this.getField("txt6").value = JSADMDlg1.company;
    this.getField("txt7").value = JSADMDlg1.project;
    this.getField("txt8").value = JSADMDlg1.job;
    this.getField("txt9").value = JSADMDlg1.costcode;
    //format amount dialog entry to round to two decial places, contain thousands commas, and have a $ symbol in front, have negative values be containted in parenthesis
    if (JSADMDlg1.amount != "") {
        var absamount = Math.abs(JSADMDlg1.amount);
        if (JSADMDlg1.amount < 0) {
            this.getField("tzt1").value = "$(" + util.printf("%,0.2f"absamount) + ")";
            } else {
            this.getField("tzt1").value = util.printf("$%,0.2f"JSADMDlg1.amount);
        };
        if (this.getField("tzt1").value.length < 13) {
            this.getField("tzt1").textSize = 11;
            } else {
            this.getField("tzt1").textSize = 0;
        };
    } else {
        this.getField("tzt1").value = JSADMDlg1.amount;
    };
    this.getField("tzt2").value = JSADMDlg1.glcode;
    if (JSADMDlg1.glcode.length < 11) {
        this.getField("tzt2").textSize = 11;
        } else {
        this.getField("tzt2").textSize = 0;
    };
    if (JSADMDlg1.duedatem == "" && JSADMDlg1.duedated == "" && JSADMDlg1.duedatey == "") {
        this.getField("tzt3").value = "";
        } else if (JSADMDlg1.duedatem == "" || JSADMDlg1.duedated == "" || JSADMDlg1.duedatey == ""){
        this.getField("tzt3").value = JSADMDlg1.duedatem + "/" + JSADMDlg1.duedated + "/" + JSADMDlg1.duedatey;
        } else {
            var tempddt = JSADMDlg1.duedatem + "-" + JSADMDlg1.duedated + "-" + JSADMDlg1.duedatey;
            var tempddt1 = util.scand("mm-dd-yy"tempddt);
            this.getField("tzt3").value = util.printd("mm/dd/yy"tempddt1);
        };
}
}
// End code
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 14, 2020 Dec 14, 2020

This should have worked:

var test1 = this.getPageNthWord(0,0);

What happens if you only enter this code:

var test1 = this.getPageNthWord(0,0);

app.alert(test1.toSource());

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 14, 2020 Dec 14, 2020

try67

 

I tried adding your code in the stamp code and neither the dialog box nor the alert dialog box show up at all, but the stamp image is still applied to a document page. I tried replacing all of the stamp code to only contain the two lines of code you posted and an alert dialog box appears with

(new String("Vendor"))

which is the first text word that is in the stamp pdf not the first word of the target pdf.

Doing some more reading I found that

this.getPageNthWord(0,0)

can be replaced with

event.source.source.getPageNthWord(0,0)

This seems to get me the first word of the docuemnt being stamped. I don't beleive I understand how this works though since I am trying to now use event.source.source.pageNum function and it does not work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 14, 2020 Dec 14, 2020

Yes, in the context of a dynamic stamp event.source.source returns the document to which the stamp is being applied. And I tried it with event.source.source.pageNum and it worked fine, by the way.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 14, 2020 Dec 14, 2020
LATEST

try67

 

Thank you for your help. You have answered the original posts question so I'll mark you correct! I think I need to do some research and tinkering to see why event.source.source.pageNum does not work but event.source.source.getPageNthWord() does work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2020 Dec 11, 2020

Since you've mentioned  about a bit of context, I think you're not using that function in the correct context.

 

I am learning JavaScript so bear with me if I say something incorrect, but you can't convert a function to string if the object itself is not defined to begin with.

 

Running the function by itself in the console is not converting anything to a string, is just reporting back. 

 

So when you say "When I try to the use the function this.getPageNthWord() or doc.getPageNthWord() and convert it to a string" is hard to make sense out of it, unless you mean that you have defined an array for example, or a for loop, with  a condition to search for a specific word. And since you've mentioned about using the function by itself, and that it finds the first word in the document, that is not a text string that was taken from a field object for example. The text string that you're referring to is taken from the free text content of your document. That doesn't necessarily mean it was found in an annotation or a comment.

 

See Example 2, in Page 232 of the Adobe Acrobat SDK JavaScript API JavaScript™ for Acrobat® API Reference "Doc methods"

 

//Example 2
//Search through the document for the word “Acrobat” and create a link around that word.

for (var p = 0; p < this.numPages; p++)
{
var numWords = this.getPageNumWords(p);
for (var i=0; i<numWords; i++)
{
var ckWord = this.getPageNthWord(p, i, true);
if ( ckWord == "Acrobat")
{
var q = this.getPageNthWordQuads(p, i);
// Convert quads in default user space to rotated
// User space used by Links.
m = (new Matrix2D).fromRotated(this,p);
mInv = m.invert()
r = mInv.transform(q)
r=r.toString()
r = r.split(",");
l = addLink(p, [r[4], r[5], r[2], r[3]]);
l.borderColor = color.red;
l.borderWidth = 1;
l.setAction("this.getURL('http://www.example.com/')");
}
}
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines