Skip to main content
Das Boomer
Known Participant
October 17, 2016
Question

Adding (failing to add) a toolbar button in Acrobat DC Pro 15.02

  • October 17, 2016
  • 2 replies
  • 869 views

Greetings,

I created a working menu item that removes, or scalps (as my user calls it), the first page of a pdf.

I am attempting to add this as a toolbar button.

Following the documentation, I wrote the following code, which I added in the Javascript folder of Acrobat DC Pro (15.02020039).

I ensured that my jpg used for the icon is 20x20. The dummy pdf is just my business card.

I placed both the jpg for the icon and the dummy pdf in the Javascript folder.

I added all this here for your convenience: AddButton - Google Drive

When I start Acrobat, nothing happens, in terms of having my button anywhere under 'Tools'.

Being this is my first button... I beg for some guidance

Here's the code I have:

var LoadScalpPdfButton = app.trustedFunction( function ()

{

   if ( typeof LoadScalpPdfButton == "undefined" )

      ScalpPdf = true;

   else

   {

      if (!LoadScalpPdfButton)

      {

         app.removeToolButton("ScalpPdf");

         ScalpPdf = true;

         return;

      }

   }

   if ( ScalpPdf )

   {

      app.beginPriv();

      // Get the path to the user JavaScript folder

      var atbPath=app.getPath({cCategory: "user", cFolder: "javascript"});

      try

      {

         // Try opening the icon doc as in hidden mode, and retrieve its doc

         // object.

         var doc=app.openDoc({

            cPath: atbPath+"/dummy.pdf", bHidden: true});

         } catch (e) { console.println("Could not open icon file"); return;}

      // Get the icon stream for myIcon1 from the hidden doc

      var iconPath = atbPath+"/scalp.jpg"

      doc.importIcon("scalped", iconPath, 0);

      var oIcon = util.iconStreamFromIcon(doc.getIcon("scalped"));

      // Add a tool button using this icon

      app.addToolButton({

         cName: "ScalpPdf",

         oIcon: oIcon,

         cExec: "ScalpPdf();",

         cTooltext: "Scalp this Pdf",

         nPos: 0

      });

// Close our hidden document containing the icons.

   doc.closeDoc();

   app.endPriv();

   // Set this variable to signal that the toolbars are installed.

   LoadScalpPdfButton = false;

   }

})

var ScalpPdf = app.trustedFunction(function()

{

   app.beginPriv();

    if (app.activeDocs.length > 0)

    {

      this.deletePages({nStart: 0, nEnd: 0});

      var myDocPath = this.path;

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

      aPathComps.pop();

      aPathComps.push("Scalped.pdf");

      var strNewPath = aPathComps.join("/");

      this.saveAs(strNewPath);

    } 

   app.endPriv();

});

Thank you for your advice.

This topic has been closed for replies.

2 replies

Inspiring
October 17, 2016

Have you added any code like an "app.alert" or "console.prntln"  to in the file outside of the function definition to see if the file holding the code has been accessed during the startup processing?

console.println(typeof LoadScalpPdfButton == "undefined"? "Function not loaded!\nYou need to call the function." : "Succes! Function loaded.");

You call the function by adding the following line at the end of your code:

LoadScalpPdfButton();

Das Boomer
Known Participant
October 17, 2016

Hello,

I followed your good advice and added the console.println at the end of the script and it appears it loaded fine.

So now, rather befuddled, I have to figure out where it, since I cannot see it in the ui.

I have added the current script in the google drive for your convenience.

AddButton - Google Drive

Thank for your time.

Antoine

Bernd Alheit
Community Expert
Community Expert
October 17, 2016

Where did you call the function?

Das Boomer
Known Participant
October 17, 2016

Greetings,

Indeed. Embarrassingly enough, I had not called the function in my code.

Coding after a long day is maybe too much for me without caffeine.

I now have Acrobat opening up and showing me on my left screen the 'dummy' pdf used in the code asking to save or not. Interesting is that in that window I at least see the section 'Add-on tools' that, whether or not I save, never actually shows my tool in the list on my right hand side screen where the pdf I opened to start acrobat is displayed.

Here's what I'm seeing:

And on the other monitor (whether or not I save this dummy pdf)...

I do not see the add-on button here.

Any help is, as always, much appreciated

Thank you,

antoine