0

My goal is to have the user press a button to select a file ONE TIME that will be used both as an attachement and the button icon. I know how to do each of these tasks separately, but this requires my user to select the same file twice. I am looking for a way to either:

  • Have them import a file as a button Icon, then change the Icon into a DataObject and attach it to the pdf
  • Have them import a file as a DataObject attachment, then convert it to an Icon

Is this possible? I haven't been able to figure this conversion step out.

Thanks

ctrl-z pls
  • 331
  • 6
  • 21

1 Answers1

0

You can prompt the user for the file to import once and then use the path for the two use cases you need.

var img = app.browseForDoc(); // prompts the user to select the file
var imgPath = img.cPath; // get the device independent path to the file
this.importDataObject("myDataObjectFileName", imgPath); // import the data object
this.getField("myImageButton").buttonImportIcon(imgPath); // set "normal" the button face

Your button must be set up to show an icon first and you'll also want to set the scaling properties as well. You can make the attachment name the same as the file name with some simple string functions on the path.

joelgeraci
  • 4,606
  • 1
  • 12
  • 19
  • This sounds like exactly what I'm looking for! But right now it isn't working. I placed this code in the button for when it gets clicked, and changed the `getField` parameter to match my button name. However when I clicked it, nothing happened. No file explorer opened to browse. What's going wrong? Thank you for your help! **EDIT:** the documentation says `browseForDoc` can only be executed during a batch or console event... So looks like I need a workaround? – ctrl-z pls Apr 04 '17 at 06:52
  • I tried also writing the code as a function in the document-level JS and then calling the function from the button when clicked, but I still can't get the file explorer prompt to pop up due to security blocks. Additionally, [this page](https://acrobatusers.com/tutorials/print/popup_windows_part3) says you can only pick pdf files with it, and I need to attach images so I don't think the function would work for me anyways :( – ctrl-z pls Apr 04 '17 at 07:37
  • I'd need to know more about who you plan on distributing this for to before I gave you the right advise on the security work around. There are a few ways but all will involve the user giving permission to the form to execute the code. However, your proposed workflow may not work at all in that with Adobe Reader, only PDF files can be assigned as button icons. Acrobat will convert the image to PDF in the background first but Reader can't. – joelgeraci Apr 04 '17 at 15:45