Skip to main content
Participant
June 6, 2017
Question

Acrobat-resizing image in form field

  • June 6, 2017
  • 2 replies
  • 4339 views

I've been asked to create a series of editable PDFs in which the user (in Acrobat) can press a button, upload a logo image, and have it be automatically placed onto the PDF.

I've solved the bulk of this problem with the usual JavaScript snippet:

event.target.buttonImportIcon();

This works well enough to allow me to upload images into the form field, but because company logos vary wildly in dimensions, design, etc., it's been difficult for me to get the logos to resize and look good. I've already explored the settings under "Icon Placement," under "Button Properties," but they simply don't work well enough.

Is there another way I can get my logo images to resize in a more effective manner? I'm thinking there might be some kind of JavaScript I can write to force the image to scale, but I'm not sure where I'd start.

Thanks!

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
November 13, 2019

Yes, there are things you can do.

First, to get the real dimensions of an image, use this code

 

var oIcon = this.getField("ButtonField").buttonGetIcon();

var stmIcon = util.iconStreamFromIcon(oIcon);

var width = stmIcon.width;

var height = stmIcon.height;

 

You can then uses these dimensions to resize the button using the "rect" property for best viewing. You'll need the scripts set the button locations so they don't overlap each other or other content on the page. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
November 13, 2019

Thanks for the response Thom.

I think I need to clarify ...

The functionality that the user sees is as follows ...

On the mouse enter of a thumbnail image field, I unhide a large, higher res field with the same image.  On the mouse exit, I hide the larger image, which allows the user to continue navigating the report.

So here is the issue ...
I have many images that will be presented in the same way on the form.  When I am creating (editing) the form for a unique user, the "Large" image fields block editing capabilities, so what I do is to set the image in small (thumbnail size) image fields.  When I am done editing the form for distribution, I need to resize and reposition all the large image fields, which is tedious and time consuming.

I have a script that I run to perform other "prep" functions (i.e. hiding fields, setting fields = read only, etc.).  I want to add functionality to that script to resize and reposition all of the (large) image fields at predetermined size and location.  This is the last step in my report preparation.  I can then distibuite.

So my issue is in programatically resizing/repositioning the image "fields" and not the field content (image).

I hope that this clarifies.  Any additional help would be greatly appreciated.  Thanks!!

 

Thom Parker
Community Expert
Community Expert
November 13, 2019

Images are scaled to fit the button field where they are displayed, so resizing the button field is resizing the image. I provided you with code for determining the real dimensions of the image. With this information you know both the aspect ratio of the image and it's maximum resolution for good viewing.

 

So what is the "predetermined size and location"? If this infomation is already known, then just risize and position the button fields? If it's not known, then is this the info you are trying to find? What exactly is the issue you are trying to solve?

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
June 6, 2017

JS can't do more than what can be done using the options you see under the

Properties dialog.

On Tue, Jun 6, 2017 at 10:36 PM, ex83181920 <forums_noreply@adobe.com>

Participant
June 6, 2017

Is JavaScript in Acrobat limited? I'm fairly sure JavaScript on a web page for example could do something like this.

try67
Community Expert
Community Expert
June 6, 2017

Yes, it's quite limited, and very different from the web-page variety...