These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Need help with images and scripting

eyal
Registered: May 2 2008
Posts: 2

Hi,

I have a difficult problem, I'm sure it'll be quite a challenge even to the JS experts around here:

I have an image on a page (logo). I make a call using SOAP to my webservice to get the logo content (the binary data of the gif file).
My problem is that although I have the data (either as a string or as a stream), I cannot assign it to the existing picture and force it to render. Can I create one dynamically in Acrobat Reader? Or do you have any idea how I can use the existing blank picture which was reserved for this purpose to be assigned with the new picture data?

Thanks in advance,
Eyal.

My Product Information:
Reader 8.1.2
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Dynamic images in a PDF (Not a LiveCycle Form) are displayed with a Button Field. There is a JavaScript function for setting a button's image, buttonSetIcon(). Unfortunately there is no easy, or practical, way to transform generic image data into an icon object.

However, given that you have already built a web service, you have another option. Use a server side script to return the image in an FDF through an HTTP Response. The "doc.submitForm()" method uses HTTP Req/Resp to communcate with a server script. You can use this mechanism to return an FDF to the PDF. Button images can be populated through an FDF.

To see how this works, place a button on a PDF and place an image in it. Then export an FDF to your local drive. Change the image and do it again, only save the FDF to a different name. Then, when the FDF is imported it sets the button image. Look in the FDF file to see how it's all formatted. The specifics are give in the PDF Specification, which you can download from here. In fact, it'd probably be a good idea to download the Acrobat SDK.

http://www.adobe.com/devnet/acrobat/

This is much, much easier than using a web service.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

v1ru5
Registered: Nov 26 2008
Posts: 5
Can you explain more about populating button images through FDF? I tried

"To see how this works, place a button on a PDF and place an image in it. Then export an FDF to your local drive. Change the image and do it again, only save the FDF to a different name. Then, when the FDF is imported it sets the button image. Look in the FDF file to see how it's all formatted"

but somehow I can't get it working. These are the steps:
1. Create a button and set image as icon
2. go to forms and export data as FDF
3. change the button with another image
4. Export the data again as FDF
5. Import different FDF, but nothing seems to happen, and when I checked the FDF it doesn't seem to contain any data regarding to the image.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Opps, The normal export from the menu item does not include button fields. Use this line of code to export just the button image data. Run it from the [url=http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/javascript_console/]Console Window[/url]

this.exportAsFDF({aFields:["Button2"]});

In this code "Button2" is the name of the button field with the image on it. Change this to the name of your button. Also, notice that it's in an array, so you can export as many image buttons as you'd like.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

v1ru5
Registered: Nov 26 2008
Posts: 5
Thx for the reply. I tried your suggestion to display button icon via fdf, but so far I have no luck displaying it in adobe reader. Is there any limitation that caused this? By the way I was using fdf that points to URL location that store the pdf image.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Is it working in Acrobat Pro?? Is the PDF Rights Enabled?? Have you tried the simplest method in Reader, i.e., just importing the exported FDF file on a Local PDF?? When you are trying somthing for the first time always simplify. Try to do one thing at a time in the simplest context or you'll never know where it went wrong.

The FDF data with the image in it can be imported into Reader with the following line of code if the PDF is Reader Enabled with Form Rights. Its in the Acrobat JavaScript Reference.

this.importAnFDF();

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

try67
Expert
Registered: Oct 30 2008
Posts: 2398
May I jump on the bandwagon for a moment?

Thom, I've been playing around with FDF files and I've noticed that if I change the button's layout from Icon Only to Label Only the image doesn't get imported. Is there a way to set this property via the FDF as well?

Also, Is it possible to create fields with an FDF, not just populate existing ones?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Yes, you can set the various field/annotation flags for a field via FDF. I haven't tried changing from text only to one of the icon layouts and setting an icon with the same FDF, however, so I'm not sure if it will work.

An FDF can contain JavaScript that executes before anything else happens, so you can create fields that way.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Thanks for the response, George.
Yes, I saw that an FDF can execute JS as well, so I guess I can just change the button's properties to "Icon only" that way.

I must say that I was quite surprised at the lack of consistency in which it works, though. Why does using exportAnFDF not export the image data of a button, but when you specify the button's name explicitly it does? And why when you're exporting using Acrobat's built-in feature the buttons are totally ignored? (I'm not asking you, it's just a general rant, really...)

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
> Why does using exportAnFDF not export the image data of a button, but when you specify the button's name explicitly it does?I think because exporting button icons is not what people would normally want, so the default is to not do it. Imagine a document with a lot of buttons but only a few fields. The FDF would be inordinately large. This follows the lead of what happens with a submit form action or the submitForm method. Since buttons don't normally represent data, I think the default behavior is reasonable.

This subject touches on a major pet peeve of mine, which is not allowing Reader to set button icons using the buttonImportIcon method. Adobe allows XFA forms to use an image field with Reader, but this no longer works with Reader with an acroform. There is no good reason for this and there is a good amount of demand. It would be great if they brought this back.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I guess what really bothers me is the lack of accurate documentation. Why do you have to guess that specifying an array of fields will work totally differently compared to exporting all the fields?

And I agree about being able to import images to buttons in Reader. It seems that Adobe is going in the right direction by enabling Reader X to add highlights without the special rights applied in Acrobat, but they neglected this bit, which is very frequently asked for.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com