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

Folder Level Script Required to add Toolbar Item

Explorer ,
Jan 08, 2018 Jan 08, 2018

Copy link to clipboard

Copied

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); 

}

TOPICS
Acrobat SDK and JavaScript , Windows

Views

2.5K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jan 08, 2018 Jan 08, 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

}

Votes

Translate

Translate
Explorer ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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 ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

This is not a public link.

Votes

Translate

Translate

Report

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
Explorer ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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 ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

I downloaded the file, renamed it to "Test.js", placed it in the JavaScripts folder and it worked just fine.

Votes

Translate

Translate

Report

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
Explorer ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

What is this error

GeneralError: Operation failed.

App.addToolButton:6:Folder-Level:User:test.js

The name for the toolbutton must be unique

NotAllowedError: Security settings prevent access to this property or method.

App.newDoc:9:App MyScript1:Exec

Votes

Translate

Translate

Report

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 ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

The first one means you have tried to add multiple tool-buttons with the same cName value.

The second one means you're trying to use a function from a normal context, while it requires a privileged one.

Votes

Translate

Translate

Report

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
Explorer ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

First error solved. Second one how to solve?

Votes

Translate

Translate

Report

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 ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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
Explorer ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

Hello Try, Since it shows error for newdoc i added privileged code, but now it is showing error for trusted function.

NotAllowedError: Security settings prevent access to this property or method.

App.trustedFunction:28:App MyScript1:Exec

myTrustedNewDoc = app.trustedFunction( function (nPage, cPath, nStart, nEnd)

{

app.beginPriv();

var myTrustedRetn = app.newDoc();

app.endPriv();

return myTrustedRetn;

});

    // 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,

        } );

    }

Votes

Translate

Translate

Report

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 ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

Convert the whole function extractSheetPages in a trusted function.

Votes

Translate

Translate

Report

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 ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

You created a trusted function but you're not using it... Instead of this:

var d = app.newDoc();

Use:

var d = myTrustedNewDoc();

And remove the input parameters for it. You're not using them, anyway.

Votes

Translate

Translate

Report

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
Explorer ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

Hello Try i am giving up. i cant make it happen. Could you please add those few line of codes in my codes.

Votes

Translate

Translate

Report

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 ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

If you'd like me to write your code for you you can contact me at try6767 at gmail.com to discuss it further, including the price.

Votes

Translate

Translate

Report

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
Explorer ,
Jan 10, 2018 Jan 10, 2018

Copy link to clipboard

Copied

LATEST

Hello Try, I finally made it. Thanks for your guidance and support.

Votes

Translate

Translate

Report

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 ,
Jan 09, 2018 Jan 09, 2018

Copy link to clipboard

Copied

Do you use addToolButton in another JavaScript file?

Votes

Translate

Translate

Report

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 ,
Jan 08, 2018 Jan 08, 2018

Copy link to clipboard

Copied

try67  wrote

I take it back, you're correct. That worked. However, it seems like a real hassle when one can simply use the pre-existing app folder...

This is possible when you can create files in this folder.

Votes

Translate

Translate

Report

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 ,
Jan 08, 2018 Jan 08, 2018

Copy link to clipboard

Copied

Bernd is correct, this error shows up when you don't have a user level folder. Are you sure you are creating it in the correct location? Starting with Acrobat 10, you need to add the "Privileged" folder to the path.

Votes

Translate

Translate

Report

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
Explorer ,
Jan 08, 2018 Jan 08, 2018

Copy link to clipboard

Copied

Hello Try, I did exactly what you instructed. I got the Toolbar but the code is not running.

Votes

Translate

Translate

Report

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
Explorer ,
Jan 08, 2018 Jan 08, 2018

Copy link to clipboard

Copied

Ok Try, thank you very much.

Votes

Translate

Translate

Report

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