Skip to main content
Participating Frequently
November 9, 2016
Question

issue with adding an icon to a button

  • November 9, 2016
  • 16 replies
  • 2178 views

I have created a trusted function (code below), when I call this function the button gets created on the page however this button is just a blank box, how do I get an image to show in the created button.  I am running this in Adobe Reader XI, which I believe should allow this functionality, if not can anyone explain how I am able to add an image to a pdf using javascript. 

app.addToolButton({cName:"TestButton", cExec:"CreateMyButton('NextButton', this.pageNum)", cLabel:"Test Button", cTooltext:"Test_Button"});

var CreateMyButton = app.trustedFunction(function(cName, nPage)

{

  app.beginPriv();

  // Acquire the crop box (visible area) for the current page

  var pgRect = this.getPageBox("Crop", nPage);

  // Build Button Rectangle in lower left corner of page

  var fldRect = []; fldRect [0] = pgRect[0] + 36;

  // 1/2 inch from left side

  fldRect [1] = pgRect[0] + 56;

  // 20 points high

  fldRect [2] = pgRect[0] + 172;

  // 1/2 inch wide

  fldRect [3] = pgRect[0] + 136;

  // 1/2 inch from bottom

  // Create Button on page

  var oFld = this.addField( cName , "button", nPage, fldRect);

  // Setup Button's Properties

  if(oFld != null) {

  //oFld.buttonSetCaption("Next");

  oFld.buttonPosition = position.iconOnly;

  oFld.buttonImportIcon("/fileserver/folder/folder2/iconimage.pdf");

  oFld.borderStyle = border.b;

  // Beveled edges

  oFld.strokeColor = color.blue;

  // Border Color

  oFld.textColor = color.black; oFld.lineWidth = 1;

  // Thin Border

  oFld.setAction("MouseUp", "this.pageNum++");

  // Navigation

  }

  return oFld;

  app.endPriv();

});

This topic has been closed for replies.

16 replies

try67
Community Expert
Community Expert
November 9, 2016

It works fine for me... Are you sure that the file-path of the image file is correct? To verify it I recommend you open that file (in Acrobat) and then run this code from the JS Console:

this.path

It will print out the file's path in the syntax that you should use in your code.

Participating Frequently
November 9, 2016

I opened the file i.e. iconimage.pdf in acrobat reader xi and launched the console and ran this.path; the resulting string is exactly the string I am using in oFld.buttonImportIcon(" ... ");

as an aside, I did move the icon image pdf into my c drive and tested the path to the new file and the code worked, so seems there is an issue with a network shared drive, even though I use the same path as this.path shows. 

In addition to the original query is there a way for the user to move the button around the pdf after it is placed like you can with other fields or does it have to remain in the static position the script placed it?

try67
Community Expert
Community Expert
November 9, 2016

Yes, the network location is probably the issue. You can try mounting that network folder as a drive and then it might work...

Users in Reader can't move fields around. Not through the standard GUI, anyway. This field is no exception.