Skip to main content
March 23, 2020
Question

Converting CSV to a list in a PDF text field

  • March 23, 2020
  • 3 replies
  • 1429 views

I use a PDF widget in an SBM (Solutions Business Manager) form to send mapped fields to a PDF form.  One of the fields is a multi-selection field in SBM, and a text field in the PDF form.  The values are displayed in the PDF form as comma-delimited.  I would like them to appear as a list.  I'm guessing that, absent a function to do this in the Acrobat > Prepare Form > [field] > Properties, I need to add a javascript to do the job, in Properties > Actions > Add javascript.  Is this the best solution, and where would I find such a script?

This topic has been closed for replies.

3 replies

April 1, 2020

For anyone following the diversion I made [I since opened a separate post for it] regarding font size, I changed the font size of my SBM field, and that is a workaround.  I will now try a javascript snippet in the PDF field > format to force the font size.

try67
Community Expert
Community Expert
March 31, 2020

You can do it by adding a doc-level script to the file, which will execute each time it opens.

Let's say the text field is called Text1 and the drop-down is called Dropdown1.

You can then use this code to set the items from the text field to the drop-down. It will also maintain the currently selected value in the drop-down, if that value appears in the list.

 

var newItems = this.getField("Text1").valueAsString.split(",");
var oldValue = this.getField("Dropdown1").valueAsString;
this.getField("Dropdown1").setItems(newItems);
if (newItems.indexOf(oldValue)!=-1) this.getField("Dropdown1").value = oldValue;

 

 

March 31, 2020

Thank you.  What does doc-level mean?  Hopefully, it is not in [field] > Properties > Format > Custom > Custom Format Script, because I thought I tested a script that put "Hello" in the text box (proof of concept), but didn't work when SBM generated the PDF.

 

The javascript command I use in the SBM form action is: 

    var convertedToList = commaDelimValue.replace(/,/g, '\n');

 

I had used a variant of that command (can't remember what it was, unfortunately, though I think I stored it someplace) in the PDF, and sure enough, after I entered values directly into the PDF field, the script worked.  It just wouldn't work with SBM generating the PDF.

 

 

also, can you think of a solution to the subsequent problem I encountered, not being able to set the font size when a rich text field in SBM is mapped to a text field (with rich text checked in Properties) in the PDF?  When I uncheck rich text in the SBM field definition, the font size responds in the PDF, but the html isn't rendered in the field content.

 

 

 

April 1, 2020

You have to set the textSize property of each Span object. Have you done that?


I'll hit the reference again.  So far, I do not know what a Span object is.  Also, I wish to understand why checking the Rich Text option works, but setting the font does not.  And, I wonder if a java snippet in Properties > Format would work.

Thom Parker
Community Expert
Community Expert
March 24, 2020

First, we need more information on how this process takes place.

1) How is this field filled? Is it done at the time the form is created by SBM? Is it done at a later time in Acrobat?

2) Is this is a one time conversion from a list of comma separated values into a multiline list?

3) What is the exact format of the data? It is a single line of text? Multiple lines?  Provide an example.

4) Is this data used for anything else after the PDF form is created? i.e. anything that would require the original format?

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
March 31, 2020

1) How is this field filled? Is it done at the time the form is created by SBM? Yes.  Is it done at a later time in Acrobat?

2) Is this is a one time conversion from a list of comma separated values into a multiline list? Yes.

3) What is the exact format of the data? It is a single line of text? Yes.   Multiple lines?  Provide an example. Apple,orange

4) Is this data used for anything else after the PDF form is created? i.e. anything that would require the original format? No.

After I found that a script I tried in the PDF Properties > Format tab had no effect, I created a script on the SBM side that converted the CSV field to a list in a Text field, then mapped the text field to the PDF field in SBM.  That works, so I have little interest in my original query to you.  My current dilemma, if I may, is that mapping rich text content to an SBM text field with or without rich text checked in PDF  > Properties, negates the PDF field font setting.