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

Field summation using fractional text

schaffs
Registered: Apr 18 2007
Posts: 4

I recently asked a question regarding formatting text fields. However, I think that I asked the wrong question. I have PDF drawings with text fields where different dimensional information is entered (and later printed). I am trying to get different fields to be summed in a seperate "total" field. The dimensions need to be displayed architecturally (fractions) and will also be entered as fractions. So far I have struggled and still not been able to figure out how to format any entered text as fractions, let alone my end goal of fractional numbers being summed and displayed fractionally.

My Product Information:
Acrobat Standard 5.0.5, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ok, so someone is going to enter a value like "1-1/2"? If this is correct then it's not formatting you want, but conversion into a number. If the format is consistent then this is actually very simple.

In the calculation script for the sum field use this code to add the entered fractions.
function convertFract(cFract){return eval(cFract.replace(/\-/,"+"));} var sum = 0;// For each Fieldsum += convertFract(this.getField("Dim1").value);
If the fomat varies then the Regular Expression in the replace function will need to be modified. The idea here is that the fraction is really a simple math expression that can be evaluated in JavaScript. You just need to massage the format a little.

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