Skip to main content
madhusudhananc
Known Participant
Jan 8, 2018 4:59 PM UTC
Answered

Folder Level Script Required to add Toolbar Item

Hello Guys i tried my level best to add my code to add in tool bar. I cant succeed. I am beginner so i unable to grasp some complicated technical terms. Anyone please add the folder scripting code to run my existing code. Below code is i am using in Acrobat 11 but now i want to do it in acrobat 9 tool bar. Please help.

// pages on which that string is found to a new file.

var pageArray = [];

var stringToSearchFor = "SHEET";

for (var p = 0; p < this.numPages; p++) {

    // iterate over all words

    for (var n = 0; n < this.getPageNumWords(p); n++) {

        if (this.getPageNthWord(p, n) == stringToSearchFor) {

            pageArray.push(p);

            break;

        }

    }

}

if (pageArray.length > 0) {

    // extract all pages that contain the string into a new document

    var d = app.newDoc();   

// this will add a blank page - we need to remove that once we are done

    for (var n = 0; n < pageArray.length; n++) {

        d.insertPages( {

            nPage: d.numPages-1,

            cPath: this.path,

            nStart: pageArray,

            nEnd: pageArray,

        } );

    }

    // remove the first page

    d.deletePages(0);

   var annots=d.getAnnots();

    for (i in annots) annots.destroy();

// Save the new document:

var myDocPath = this.path;

var aPathComps = myDocPath.split("/");

var myFilename = aPathComps[aPathComps.length-2]; // Last element

d.saveAs("/c/QC Tool/Art Pages/"+ myFilename+".xlsx", "com.adobe.acrobat.xlsx");

d.closeDoc(true); 

}

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Jan 8, 2018 5:14 PM UTC

You put your code in a function and then call that function using the cExec method of addToolButton, like this:

app.addToolButton({ cName: "MyScript1", cLabel: "Extract SHEET Pages", cTooltext: "Extract SHEET Pages",

    cExec: "extractSheetPages()", cEnable: "event.rc = (event.target != null);"});

  

function extractSheetPages() {

    // put the rest of your code here

}

43 replies

madhusudhananc
Known Participant
Jan 8, 2018 5:23 PM UTC

Ok Try, thank you very much.

Translate
try67
Community Expert
Community Expert
Jan 8, 2018 5:03 PM UTC

Do you have the Acrobat JavaScript API Reference? Did you read the documentation of the addToolButton method?

Translate
madhusudhananc
Known Participant
Jan 8, 2018 5:08 PM UTC

Hello Try, i read that document. I understand the concept of app.addtoolbutton(). But i dont know how to link my code with that.

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Jan 8, 2018 5:14 PM UTC

You put your code in a function and then call that function using the cExec method of addToolButton, like this:

app.addToolButton({ cName: "MyScript1", cLabel: "Extract SHEET Pages", cTooltext: "Extract SHEET Pages",

    cExec: "extractSheetPages()", cEnable: "event.rc = (event.target != null);"});

  

function extractSheetPages() {

    // put the rest of your code here

}

Translate