populate form from .net using itextsharp but custom calculation script does not see value in text box

New Here ,
Nov 27, 2017

Copy link to clipboard

Copied

I am using .NET C# to populate hidden fields in a PDF form.  I then have written a custom calculation field to concatenate these field values with text to form a dynamic paragraph.

I've temporarily removed the hidden property so that I could troubleshoot and when the PDF form comes up I can see these fields have populated.  However the custom calculation script does not seem to see these values as it only shows the 'hardcoded' text from the script.  To simplify the script, I removed all fields to be concatenated except one.  I then put a default value into the text field that would normally get its value from itextsharp.  I then did a preview and the custom calculated field shows the text that I want it to with the default value from the text field.  I am assuming this means the custom calculation javascript is written correctly.

For a bit of an explanation on the fields:

CustName: is the field that I expect to receive the value from the C# (itextsharp) program

FirstParagraph: is the field that has the custom calculation javascript

I believe that my problem is that the custom calculation field is calculated BEFORE the text field is populated by itextsharp.  I have tried moving the FirstParagraph field to the bottom using the "Set Field Calculation Order".  However, since CustName receives its values from itextsharp  and is not calculated it does not show up in this listing.  I tried making CustName a calculated field by putting a custom calculation script in it.  I then moved FirstParagraph field to be AFTER CustName in the order of calculation.  still nothing appears except the 'hardcoded text'.

Here is my custom Calculation that is associated with the field FirstParagraph:

     var Cust = this.getField("CustName").value;

     event.value ='WHEREAS, the undersigned ' + Cust;

I've also tried just a straightforward assignment:

      event.value = 'WHEREAS, the undersigned ' + this.getField("CustName").value;

I've also tried ".valueAsString" as a method

None of these have retrieved the information that is passed in.  Please keep in mind the first example retrieves the DEFAULT VALUE of the field CustName, if I put one in.

Any help you can offer is appreciated.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

967

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

populate form from .net using itextsharp but custom calculation script does not see value in text box

New Here ,
Nov 27, 2017

Copy link to clipboard

Copied

I am using .NET C# to populate hidden fields in a PDF form.  I then have written a custom calculation field to concatenate these field values with text to form a dynamic paragraph.

I've temporarily removed the hidden property so that I could troubleshoot and when the PDF form comes up I can see these fields have populated.  However the custom calculation script does not seem to see these values as it only shows the 'hardcoded' text from the script.  To simplify the script, I removed all fields to be concatenated except one.  I then put a default value into the text field that would normally get its value from itextsharp.  I then did a preview and the custom calculated field shows the text that I want it to with the default value from the text field.  I am assuming this means the custom calculation javascript is written correctly.

For a bit of an explanation on the fields:

CustName: is the field that I expect to receive the value from the C# (itextsharp) program

FirstParagraph: is the field that has the custom calculation javascript

I believe that my problem is that the custom calculation field is calculated BEFORE the text field is populated by itextsharp.  I have tried moving the FirstParagraph field to the bottom using the "Set Field Calculation Order".  However, since CustName receives its values from itextsharp  and is not calculated it does not show up in this listing.  I tried making CustName a calculated field by putting a custom calculation script in it.  I then moved FirstParagraph field to be AFTER CustName in the order of calculation.  still nothing appears except the 'hardcoded text'.

Here is my custom Calculation that is associated with the field FirstParagraph:

     var Cust = this.getField("CustName").value;

     event.value ='WHEREAS, the undersigned ' + Cust;

I've also tried just a straightforward assignment:

      event.value = 'WHEREAS, the undersigned ' + this.getField("CustName").value;

I've also tried ".valueAsString" as a method

None of these have retrieved the information that is passed in.  Please keep in mind the first example retrieves the DEFAULT VALUE of the field CustName, if I put one in.

Any help you can offer is appreciated.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

968

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 27, 2017 0
Most Valuable Participant ,
Nov 27, 2017

Copy link to clipboard

Copied

No field is changed in Acrobat so no calculation is going to take place. Since you're using a third party tool that doesn't process the JavaScript, you probably need to replicate the effect of the JavaScript (and set the calculated result).

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 27, 2017 0
New Here ,
Nov 28, 2017

Copy link to clipboard

Copied

thanks for your response.  is there any way to kick off a document level javascript in the PDF form that would then call the associated calculation if i wrapped it in a function?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2017 0
New Here ,
Nov 28, 2017

Copy link to clipboard

Copied

I've wrapped the code for the text field FirstParagraph's calculated field in a function:

function UpdateFirstParagraph()

{

   var Cust = this.getField("CustName").value;

    event.value ='WHEREAS, the undersigned ' + Cust;

}

Then I've added a document level javascript in hopes that it would run the

/*********** belongs to: Document-Level:UpdateFirstParagraph ***********/

function UpdatetParagraphs()

{

   FirstParagraph.UpdateFirstParagraph();

}

still does not update the text field FirstParagraph.

i was under the impression that any Document Level code was run upon form open.

Any suggestions?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2017 0
Adobe Community Professional ,
Nov 28, 2017

Copy link to clipboard

Copied

You must execute the function UpdatetParagraphs.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2017 0
New Here ,
Nov 28, 2017

Copy link to clipboard

Copied

it doesn't automatically run when the form opens?  i was under the impression that document level functions were run when the form opens?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2017 0
Most Valuable Participant ,
Nov 28, 2017

Copy link to clipboard

Copied

Perhaps you could set one of the values, on document open. But the whole thing fails if the PDF is opened in a non-JavaScript viewer, which most PDF files are. Really, you need to make sure the calculations are done when you fill the PDF.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2017 0
New Here ,
Nov 28, 2017

Copy link to clipboard

Copied

thank Test Screen Name.  didn't see your reply before adding my last response.

it appearsto open in acrobat.  i can edit the document that opens with all of the acrobat tools and save it so i would say all of the functionality is there. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2017 0
Most Valuable Participant ,
Nov 28, 2017

Copy link to clipboard

Copied

1. The code defined in document level scripts together makes a chunk of JavaScript. This is executed when the document opens (in a viewer that supports JavaScript).  Usually this contains a series of function definitions, which are then available throughout the form's lifetime as an open document. It would be quite wrong to run them automatically, because they might need to be run at a special time e.g. when submitting, or to issue an error message. But that chunk of JavaScript can contain anything else including setting variables and calling the functions you have defined, if you want.

2. When writing forms some people don't consider their audience carefully enough, which is why I mention this. For you the form opens in Acrobat. Are you the only user of the form? If so, that's fine. If not, you need to consider what happens to people for example who open the PDF in Chrome, or Outlook, or their iPhone, or whatever. Certainly you cannot in general rely on JavaScript working or form fields being fillable or visible.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2017 1
New Here ,
Nov 28, 2017

Copy link to clipboard

Copied

these forms will be used locally (on our network) by a group of individuals that need them auto populated from a web application that they will be using.   Their machines are defaulted to open PDFs with Adobe Reader.  The web application will be run from Chrome.  The web application enables them to choose forms and data to be populated to the forms.  the user then chooses a "Print" button which kicks off the code that runs the itextsharp and opens the chosen forms.

Given that i have written a function at document level that calls the function in the text field FirstParagraph Custom Calculation, I do not understand why it is not kicking off the function.  Do i have the call written correctly at the document level?

function UpdatetParagraphs()

{

   FirstParagraph.UpdateFirstParagraph();

}

I'm a bit puzzled as why you would not want to run functionality when a form opens.  Especially if the function is going to be updating the form with information?  would you mind explaining your thought process a bit more?

thanks again

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2017 0
Most Valuable Participant ,
Nov 28, 2017

Copy link to clipboard

Copied

Those four lines

function UpdatetParagraphs()

{

   FirstParagraph.UpdateFirstParagraph();

}

define a function named UpdatetParagraphs. That is all that they do. The function now exists. If you want to call it, call it. To see why you might not want a function called automatically consider the function

function FatalError()

{

  app.alert("There has been a serious problem. Please telephone extension 232 immediately") ;

}

Clearly functions must be called only when needed, and most functions are not needed at open time.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2017 0
New Here ,
Nov 28, 2017

Copy link to clipboard

Copied

Given your reasoning for when to call a function, i would say that i am OK with calling the function that i need at Open.

the function that you show in your last reply is the function that i'm assuming should be called when the Form is opened--as it is written without any further code?  That function calls the function that i want run under the custom calculation for the text field CustName.  it does not seem to be calling it so my last question was do i have the call written correctly? ie do i need to preface the function name with the name of the text field? or something else?

<NAME OF TEXT FIELD>.<NAME OF FUNCTION IN THE CUSTOM CALCULATIONS> ? as in

FirstParagraph.UpdateFirstParagraph();

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2017 0
Adobe Community Professional ,
Nov 28, 2017

Copy link to clipboard

Copied

Use only: UpdateFirstParagraph();

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 28, 2017 0