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

Fill variable forms on going... and format it

mmaarrqquueess
Registered: Oct 8 2009
Posts: 4
Answered

Hello all,
I'm newbie here, please forgive me if I ask something ridiculous, but...

Well I have a web application that uses a PDF form to generate a client report. This report contain some variable data and I cannot have been sucess on formatting then because (I think) the keystroke or format event dosen't occurs after that the variables are filled by the application. I cannot do the formatting before fill variable at form because data are obtained by a "black-box" component.

My JScripts are working fine, because if I open PDF file generated by the app, give focus on field that contain a text unformatted and leave it by a TAB, formatting occurs ok.

Anyone knows if its possible to format a field value on this situation?

Thanks in advance!

Best regards,

Rodrigo

My Product Information:
Acrobat Pro 7.0.2, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you are filling fields on the server side using a 3rd party tool, then the JavaScript formatting is never run because there is no engine to run it. When the document is opened in Acrobat all the fields are already stable to there is no reason for Acrobat to run the formatting.

So you have a couple of options. Since this is a report there is no reason the document the client recieves needs to have interactive fields on it. At least not for the fields the server is pre-filling. So why not remove the format scripts, make the fields readOnly, and fill the fields with formatted values.

The other solution is a bit awkward. Write document level script to touch all the fields on the form using the "field.focus()" function. To keep this script from running every time the PDF is opened use a hidden field to hold a state variable. The problem with this solution is that the fields will need to have "readOnly" set to false and the user will have to save the file afterward. So it's much more problematic that just setting up formatted values in the first place.

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]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

mmaarrqquueess
Registered: Oct 8 2009
Posts: 4
Thanks for your answer thomp!
If I choose the second way, even its more problematic, I can't leave fields with ReadOnly set to false. Can I format then and after set ReadOnly to true?
Where can I write a document level scripts? Menu "Advanced > JavaScript > Set Document Actions"? Which Action?
Thanks again
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, you can set the fields to ReadOnly during the refresh process. In fact you can use this as a filter for deciding which fields to refresh. You should have a field that is always last, for example a button. So that the last text field will get the On Blur Event.

Before getting too deep into this I'd suggest doing a test with a small document script.
Here's an article on Doc Scripts:
http://www.acrobatusers.com/tutorials/2007/07/js_document_scripts

Do something like this:
var oPreFld = null;for(var i=0;i<this.numFields;i++){var cFName = this.getNthFieldName(i);var oFld = this.getField(cFName);if(!oFld.readonly && (oFld.type == "text")){oFld.setFocus();if(oPreFld)oPreFld.readonly = true;oPreFld = oFld;}}this.getField("LastField").setFocus();oPreFld.readonly = true;

I haven't tested anything, I just wrote it out as I thought about it so this code may not work as is.

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]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

mmaarrqquueess
Registered: Oct 8 2009
Posts: 4
thomp, thank you very much!
I just put this code below at document level and leave formatting functions at field level and it works fine:
for(var i=0;i<this.numFields;i++){var cFName = this.getNthFieldName(i);var oFld = this.getField(cFName);oFld.readonly = false;oFld.setFocus();oFld.value = oFld.value;oFld.readonly = true;}