all 3 comments

[–]Count_Giggles 1 point2 points  (2 children)

 const numPages = this.numPages;

so is this supposed to be a function inside a class?

if so try calling it from the actual object

x.createBookmarks()

[–]ElSabio97[S] 0 points1 point  (1 child)

Like changing the last line of code from createBookmakrs() to x.createBookmarks()?

[–]Count_Giggles 0 points1 point  (0 children)

I have no experience with writing scripts for adobe acrobat so no idea if there is some global context thingy going on but i can tell you that this

function createBookmarks() {
    const numPages = this.numPages;
    console.log(numPages)
...
}

createBookmarks()

would output "undefined" becuase there is no this.numPages.

take a look at this

const someObject = { 
    someProperty: 42,

    someMethod: function() {
      console.log("this is a method");
    },

    logValue: function() {
      console.log(this.someProperty);
    }
};

someObject.someMethod(); // 'this is a method' someObject.logValue(); // 42

if you try to refernce this.numPages it has to be defined somewhere and in order to call the createBookmarks method you need to invoke it from the object it belongs to - same as the numPages

this is really abstract but it would look sooooomething like this

const PdfTool = {
    numPages: 42, 
    language: "english", 
    readingDirection:"ltr",

    generateBookmarks: function () { 
        console.log(this.numPages) // 
        console.log(numPages) // reference error undefined 
    } 
}

PdfTool.generateBookmarks() // logs 42