• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Splitting Field contents based on line count

Explorer ,
May 06, 2019 May 06, 2019

Copy link to clipboard

Copied

I need a solution in place to split a multi line field at a certain point and fill the remaining split text into another field. I have three multi-line fields named Field 1, Field 2, and Field 3. I should say that data is not typed into these fields but rather is populated via a series of functions that grabs data from the other form fields and summarizes results in Field 1. If data does not fit in Field 1 I would like the text to overflow into Field 2..and so on. I already have the code to populate the fields.

I had the idea that the easiest way to do this count the number of paragraph returns and then split when a certain number is reached. I know how to count the returns but not sure how to implement splitting overflow..

So for example, if I have this code:

var count = 0;

var s = getField("Field1").valueAsString;

for (var i = 0; i < s.length; i++) {
    if (s === "\r") count += 1;
}

....and I want to split the text at 50 returns.. then fill Field2.

Can this be done? Maybe there is an easier way than counting returns?

Thanks in advance.

TOPICS
Acrobat SDK and JavaScript

Views

155

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
community guidelines

correct answers 1 Correct answer

Community Expert , May 06, 2019 May 06, 2019

You can use the slice method to return part of an array. See: JavaScript Array slice() Method

Likes

Translate

Translate
Community Expert ,
May 06, 2019 May 06, 2019

Copy link to clipboard

Copied

You can use the slice method to return part of an array. See: JavaScript Array slice() Method

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
community guidelines
Community Expert ,
May 06, 2019 May 06, 2019

Copy link to clipboard

Copied

LATEST

Here's an article on almost this exact topic.

https://acrobatusers.com/tutorials/splitting-and-rebuilding-strings

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
community guidelines