Expand my Community achievements bar.

Search & Replace objects (image to image field) within LCD?

Avatar

Level 1

Hi everybody,

I was wondering if there is a possibility to create a script which supports an automated sequence.

I planned to run through an imported PDF file while searching for "images"-type objects with a certain "tag". When such an object is found, it should be replaced by an "image field" type object.

Is it possible to implement this type of function?

Thanks!

Best regards,

andrejtmtld

5 Replies

Avatar

Former Community Member

I believe you can't do exactly what you mean.

These days, I am working a lot with Acrobat which has many script features in common with LiveCycle. Now, in Acrobat, you meet a lot of security issues when trying to add/remove fields at runtime. I believe Adobe people must have adopted the same approach for LiveCycle because most of the work done with it, will be converted to a pdf, i.e. mainly Acrobat or Reader objects.

This is where I got to:

var nodeList = xfa.form.form1.mainSub.nodes;

for (var i = 0; i < nodeList.length; i++){

     if (nodeList.item(i).className == "draw"){

         var fType = nodeList.item(i).ui.oneOfChild.className;

         if (fType == "imageEdit"){

             xfa.host.messageBox("First Check: "+ nodeList.item(i).name);

             var myField = nodeList.item(i);

             var url = myField.resolveNode("value.#image").href;

             xfa.host.messageBox("Second Check: "+url);

         }

     }

}

See these:

http://andrewalbrecht.com/content.php?pageID=76

http://help.adobe.com/en_US/livecycle/9.0/designerHelp/

(Scripting --> Scripting Reference --> Scripting Objects --> Image)

As you can see, I can capture a static image. I'll find all of them. I think you can go further and select the ones you identified by a tag. Actually, what do you mean with "tag"? A tooltip?

Anyway, I believe you can get to the URLs the images you are interested in are pointing to. Now, if you were able to delete a static image and add a corresponding image field, you could assign the retrieved URLs to these freshly created fields.

At this point I found these:

http://help.adobe.com/en_US/livecycle/9.0/designerHelp/

(Scripting --> Scripting Reference --> Scripting Methods --> createNode; watch out the note and consider that a static image is a draw; however, in this case, you need to create an image field)

http://help.adobe.com/en_US/livecycle/9.0/designerHelp/

(Scripting --> Scripting Reference --> Scripting Methods --> remove)

and this:

http://forums.adobe.com/thread/694384

However, it seems that though dataNodes can be created and deleted, I don't come to any changes of the form itself. I tried with

xfa.form.remerge();

or

xfa.form.recalculate(1);

and similarly with xfa.form.model object with no success.

I don't know whether I am doing something wrong here.

Anyway, I see only two alternatives:

1) hide and show fields: I think this is not of your interest because you are not creating the form from scratch (here you should prepare the form in advance with as many image fields as static images you intend to use and switch between those 2 kinds of object);

2) hide one static image and add a corresponding new instance of an hidden subform which contains just an image field you provide the right URL to. I think the instanceManager can work with subforms only:

http://help.adobe.com/en_US/livecycle/10.0/DesignerScriptingRef/WS92d06802c76abadb-3e14850712a151d27...

Following one the many tutorials around:

http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000847.html

http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000177.html

http://help.adobe.com/en_US/livecycle/10.0/DesignerScriptingRef/WS92d06802c76abadb-3e14850712a151d27...

you can reach the same effect as the static images were removed and image fields were created.

Avatar

Level 1

Thanks for the answer.

I realize that you mention the creation of field in realtime.

This is not exactly, what I mean...

So far my approach with Adobe Acrobat is based on SEQU batch processing files. 

Does such a similar batch processing method exist for Adobe LiveCycle Designer?

Thanks!

Avatar

Former Community Member

Personally, I would have attempted this job in Acrobat but there you don't have image fields so I see why you are investigating inside LiveCycle (updates about this from PS1 to PS4 below).

I don't know whether LiveCycle has an equivalent Acrobat SEQU batch processing.

However, you could still try the approach I explained above. Take this example:

you have a LiveCycle table and wish to change the total row count from 1 to 10. Though you can easily do it at design time, you may also do it at runtime.

In the latter case, you need to place a button on the form, add a script working with instanceManager as previously said. Save your form as a dynamic pdf file and run the script once. Now, you'll have a table with 10 rows. Save this file. Reopen it in LiveCycle and remove the button.

You can follow the same procedure to accomplish your task.

What I didn't say in my previous post is that if you followed the instanceManager solution, you'll have to check how to correctly position your new instances. I think this is a another major issue of that kind of approach.

Anyway, let's call in other experts at this point to first check whether LiveCycle can run SEQU batch processing.

PS1: You might also follow this route: by an Acrobat batch, just add a small "Load new image" button next to each image and use "addScript" to allow it to effectively load a new URL once clicked.

PS2: Well, actually buttons can be icon-only. So, you may play with buttons like they were image fields. Again, you need to investigate how to correctly position them.

PS3: there's one problem with Acrobat: some fields made with LiveCycle are not recognized at high level (JS). Buttons, for instance, can be handled in Acrobat by JS even though they were created in LyveCycle. However, static images might not be so.

PS4: in regard to PS3, read the Adobe JS Reference at XFA and XMLData and in particular "PDF documents that return true to the Doc dynamicXFAForm property can use the XMLData object but cannot have its form fields manipulated by that object, because the two data DOMs are isolated from each other".

Maybe, you should consider to save your form as static in LiveCycle if applicable.

Avatar

Level 10

You can create macros for Designer (ES2 or higher neccessary) to automate processes.

This can be a find & replace process for example.

Here's a sample macro with a flex UI to find and replace strings you could use to create your own macro.

https://workspaces.acrobat.com/?d=9cIUmSVH*EmQqWZtpj7Nzg

It's not neccessary to use an UI in any case. If you only need a specific action to proceed, you can simply write a JavaScript to execute.

Here are some basic information of the macro API.

http://blogs.adobe.com/formfeed/?s=macro

And here a few more macros.

http://thelivecycle.blogspot.de/search/label/Macro

Avatar

Level 1

@radzmar: I already found this page (http://thelivecycle.blogspot.de/2011/06/field-designer-macro.html) which introduces script macros for LCD. I was not able to write any JavaScript code except debug commands.

BTW: Would it work to try to convert the PDF to an XDP file and do all work on the XDP?