Jump to content

Place a Graphic File based on a Text field


Recommended Posts

Hi all,

I have a project with an Image Collection with about 600 files on different formats (12345.tif, 23456.eps, 34567b.png...).

The images are “named“ with a reference/sku (12345, 23456, 34567...).


In the project, the user will type a reference in a text field, and I have to build the page with the correct image based on the text field.


I can't build a Switch ruel as the images names are not constant (PNG/GIF/TIF... and there might be some suffixes like 34567b.


So what may I do ?


I will also have to add some new images along the year corresponding to new references and I don't want to edit a long long rule :)


Any idea ?


Best regards



Acrobat X

FusionPro 10.1

Link to comment
Share on other sites

I can think of two ways to do this.


First way: Add all the graphics as named resources in the Resources dialog. If you make each resource name match a value in the data, then you don't need any JavaScript at all. Just go into the Field editor (from the menu in Acrobat, FusionPro -> Data Definition -> Edit Fields, select your field, click Edit), and change the field's type to Graphic. Then you can select the field directly as the variable name in the Frame Properties palette.


Second way: Write the rule to try different graphic filename extensions, like so:

var baseName = Field("YourFieldName");
var extensions = [".tif", "gif", ".png", ".jpg"];
for (var i in extensions)
   var pic = CreateResource(baseName + extensions[i], "graphic", true);
   if (pic.exists)
       return pic;

Print("Graphic " + baseName + " not found.");
return NullResource();


The first way is a bit more setup but will compose more quickly and be more reliable.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...