Skip to main content
madhusudhananc
Known Participant
January 8, 2018
Answered

Folder Level Script Required to add Toolbar Item

  • January 8, 2018
  • 2 replies
  • 4252 views

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 has been closed for replies.
Correct answer try67

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

}

2 replies

madhusudhananc
Known Participant
January 8, 2018

Ok Try, thank you very much.

try67
Community Expert
Community Expert
January 8, 2018

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

madhusudhananc
Known Participant
January 8, 2018

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

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 8, 2018

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

}