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

Counting number of lines in a multirow field

chrisdedobb
Registered: Apr 25 2011
Posts: 5

I know how to count characters of a textfield but I now need tobe able to count the number of rows/lines in a multirow textfield.
 
Is this possible? Anyone willing to elaborate on how to do this?

My Product Information:
Acrobat Pro 10.0.2, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Do a search on this site for "count words lines", and you'll find plenty of info.

But keep in mind that counting the number of hard new lines is different than counting the number of lines in a multi-line text box. That is a much more difficult proposition.

If the word and line counting script don't help, then please explain what it is that needs to be accomplished. Maybe there is a different way.


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

chrisdedobb
Registered: Apr 25 2011
Posts: 5
I am doing the search now, thanks!

Just an FYI as to what I am attempting to do...

I have a multi-line text box that is being calculated from the results of 6 other fields.

What I need is a display that will indent/tab each line so that the contents appear to be a bulleted list.

I thought if I could detect a new line from the word wrap taht I might be able to insert a /t? I know what I need to do is difficult if even possible but that is what I need as the results are being used in a copy and paste and I need the formatting to be specific.

Here is my code:
(function () {

var v1 = getField("txtMAJFUNC1").value;
var v2 = getField("txtMAJFUNC2").value;
var v3 = getField("txtMAJFUNC3").value;
var v4 = getField("txtMAJFUNC4").value;
var v5 = getField("txtMAJFUNC5").value;
var v6 = getField("txtMAJFUNC6").value;

var vFINAL = ''

if ((v1 != null) && (v1 != ''))
vFINAL = vFINAL + String.fromCharCode(149) + ' ' + v1 + '\n';
if ((v2 != null) && (v2 != ''))
vFINAL = vFINAL + String.fromCharCode(149) + ' ' + v2 + '\n';
if ((v3 != null) && (v3 != ''))
vFINAL = vFINAL + String.fromCharCode(149) + ' ' + v3 + '\n';
if ((v4 != null) && (v4 != ''))
vFINAL = vFINAL + String.fromCharCode(149) + ' ' + v4 + '\n';
if ((v5 != null) && (v5 != ''))
vFINAL = vFINAL + String.fromCharCode(149) + ' ' + v5 + '\n';
if ((v6 != null) && (v6 != ''))
vFINAL = vFINAL + String.fromCharCode(149) + ' ' + v6 + '\n';

event.value = vFINAL;

})();


Here are the results:
• Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fermentum congue. Sed at enim adipiscing odio vestibulum fringilla.
• Nullam ac erat justo. Ut varius diam nec orci lacinia a convallis risus suscipit. Quisque eget justo at lacus tincidunt hendrerit. Suspendisse in libero odio. Nunc rutrum sapien vitae risus viverra ullamcorper.
• Phasellus consectetur tempor risus, in vulputate sapien varius ac. Pellentesque pretium ullamcorper libero, nec auctor lectus eleifend non.
• Nulla quis turpis odio. Proin congue arcu vitae libero feugiat accumsan. In eu velit et orci placerat mollis et sit amet lacus.

Here are the desired results:
• Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fermentum congue. Sed at enim
adipiscing odio vestibulum fringilla.
• Nullam ac erat justo. Ut varius diam nec orci lacinia a convallis risus suscipit. Quisque eget justo at lacus
tincidunt hendrerit. Suspendisse in libero odio. Nunc rutrum sapien vitae risus viverra ullamcorper.
• Phasellus consectetur tempor risus, in vulputate sapien varius ac. Pellentesque pretium ullamcorper libero,
nec auctor lectus eleifend non.
• Nulla quis turpis odio. Proin congue arcu vitae libero feugiat accumsan. In eu velit et orci placerat mollis
et sit amet lacus.

I would be OK with:
• Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fermentum congue. Sed at enim
adipiscing odio vestibulum fringilla.
• Nullam ac erat justo. Ut varius diam nec orci lacinia a convallis risus suscipit. Quisque eget justo at
lacus tincidunt hendrerit. Suspendisse in libero odio. Nunc rutrum sapien vitae risus viverra ullamcorper.
• Phasellus consectetur tempor risus, in vulputate sapien varius ac. Pellentesque pretium ullamcorper
libero, nec auctor lectus eleifend non.
• Nulla quis turpis odio. Proin congue arcu vitae libero feugiat accumsan. In eu velit et orci placerat
mollis et sit amet lacus.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
It looks like your desired formatting is not coming through on the post. Not surprising.

Trying to code a complex formatting like this is very difficult. The JS model doesn't provide enough info and in the end the code will be fighting with Acrobat.

But you might be able to do this with Rich text formatting. There are lots of fancy options. Look on the "Window > Paragraph" menu item in LiveCycle Designer.

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

chrisdedobb
Registered: Apr 25 2011
Posts: 5
OK, I have not used LiveCycle until yesterday as I did not even know it existed. It also appears that the syntax is different for Javascript?

I think I might be able to get what I want from this since it allows the text fields to grow with content size. Thanks for sending me that direction.

I have a field that is calculating. Here is my code:

topmostSubform.Page1.txtFOOTER::calculate - (JavaScript, client)
this.rawValue = TITLE.value + ", " + PPSRSGR.value + " PD#:" + PD.value;

Here is the result:
[object XFAObject], [object XFAObject] PD#:[object XFAObject]

Here is what I was expecting:
TEST, TEST2 PD#:TEST3

What am I missing? I have been looking at this all day.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
In LiveCycle scripting the value of a "Field" is acquired with the "rawValue" property, so you were close. Actually "rawValue" is a shortcut to the "value.text.value" object chain. Which is why the object references are showing up in the result.

However, I may have steered you a bit wrong. When I wrote the last post I was thinking you were already working with LiveCycle. My bad. Fortunately, it looks like you have found some advantage in the expandable fields. But there is actually a very good way for you to format the calculated text in an AcroForm (i.e. regular PDF form), and that, is to use rich text.

Look up the "spans" object in the Acrobat JavaScript reference. There's actually quite a bit more options to this object than listed in the reference. Although they are not necessarily reliable. The strategy would be to break the text into sections using the CR as a delimiter. Then place each section into a separate span object with the appropriate format settings.

To find the proper settings, set the field formatting manually from the properties toolbar. Then, using JavaScript in the console window, pick apart the field's richContents object to see the settings used by the individual spans.

Since this field is calculated, the rich text formatting should be added by the calculation script, so everything happens in one place.

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

chrisdedobb
Registered: Apr 25 2011
Posts: 5
Thom Thanks for all of your help so far. I really appreciate you taking that time to explain some of these things to me.

I had misread some the documentation for LiveCycle and did not change the references from ".value"

This fixed my issues is LiveCycle so I will continue exploring this tool as it might have some other benefits.

But, to try to stay on target with my current project I will also look into this spans business in acroforms. I am familiar with the syntax here already and can at least provide completed project more timely this way. That will give me time to research LiveCycle and really figure out what I am doing.

I will post back what I figure out with the spans as I go.

Thanks again!!
chrisdedobb
Registered: Apr 25 2011
Posts: 5
Is there a function that can be used to display the richtext code of a field? I thought escape() but it does not appear to do what I thought.

Basically a made a new field and pasted in the results in the format I wanted from a rich text editor and it kept the indentions from the bulleted list. I just need to see what/how the span was used to do this.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Rich text is not always reliable or easy to figure out. It's not documented all that well:(

But there are some tricks. Run this code in the console window.

// Returns array of span objects
rVal = getField("MyRichField").richValue;

//Display contents of first span object
rVal[0].toSource();

// Convert spans to psuedo XHTML format
util.spansToXML(rVal);

//No all formatting is saved to the spans object,
//some formatting options are internal to Acrobat
// This code tests the formatting options that can be scripted
// To use it:
// 1) Add two rich text fields to form
// 2) Add manually formatted text to one
// 3) run this code

getField("RichTxt2").richValue = getField("RichTxt1").richValue;



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