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

Rich Text Formatting and Java Script Editable PDF

Explorer ,
Jan 25, 2017 Jan 25, 2017

Copy link to clipboard

Copied

So, through this forum, (thank you  Almir R V Santos ) I have learned how to have text displayed when I have created editable text boxes in acrobat that have set character spacing by inserting in to Custom Format Scripts in Text Field Properties......

var text = event.value;
if (!text) {
  text
= "Your name here";
}

text
= text.split("").join(" ");
event.value = text;

Can we take this one step further and allow Rich Text Formatting so that the client can go into the Reader enabled version and change text size and color?

I have been trying to work this out for over a year! You can certainly tick rich Text Formatting but it does not allow text size, font etc changes in Reader, only actual wording. What am I missing?

Thanks in advance!

Karen Thring

TOPICS
Edit and convert PDFs

Views

4.0K

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 , Jan 26, 2017 Jan 26, 2017

You can try something like this, it should work for both Rich Text and normal fields:

var haveText = false;

if (event.value.length > 0)

  haveText = true;

if (event.target.richText && event.richValue.length > 0)

  haveText = true;

if (!haveText) {

  text = "Your name here";

  event.value = text;

} else {

  if (event.target.richText) {

  var spans = event.richValue;

  if (spans.length == 0) {

  text = text.split("").join(" ");

  event.value = text;

  } else {

  for (var i = 0; i < spans.length; i++) {

  spans.tex

...

Votes

Translate

Translate
Community Expert ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

In Acrobat Reader select the text and press ctrl-e.

Votes

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
Explorer ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

Thank you for your answer Bernd but that does not work. In Reader, when you try to change size etc it reverts immediately. I am hoping there is an addition to Almir R V Santos's code above that will allow Rich Text formatting to work even with character spacing set.

Votes

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 ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

With this simple script, you cannot have both the extra space between characters and rich text formatting. It's one or the other. If you want both, you will have to come up with a much more complex script that also takes the formatting commands into account.

BTW: If you are referring to an older discussion, it's always useful to add a link, so that we are all on the same page.

Votes

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
Explorer ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

Thank you Karl, the original discussion was here

Java Script to allow character spacing in editable PDF? (Edit PDF) https://answers.acrobatusers.com/Java-Script-character-spacing-editable-PDF-q303378.aspx

Where / how could I go about getting someone to look at this complex script for me? It is very integral to my work.

Thanks so much in advance

Karen

Votes

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 ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

You can try something like this, it should work for both Rich Text and normal fields:

var haveText = false;

if (event.value.length > 0)

  haveText = true;

if (event.target.richText && event.richValue.length > 0)

  haveText = true;

if (!haveText) {

  text = "Your name here";

  event.value = text;

} else {

  if (event.target.richText) {

  var spans = event.richValue;

  if (spans.length == 0) {

  text = text.split("").join(" ");

  event.value = text;

  } else {

  for (var i = 0; i < spans.length; i++) {

  spans.text = spans.text.split("").join(" ");

  }

  event.richValue = spans;

  }

  } else {

  text = text.split("").join(" ");

  event.value = text;

  }

}

The only thing that does not work is the link feature in a Rich Text field.

[ Update: There was a problem with my code and I had to modify it. ]

Votes

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
Explorer ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

Amazing!!! Thank you so much Karl. You have made my year and halved my work load. Thank You!

Votes

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
Explorer ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

Hi Karl, one final question, this works great but does not show the text that can be overtyped. No biggie I can live without it but is there a way that text can show? That may be an element of the link feature that you mentioned.

Karen

Votes

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 ,
Jan 27, 2017 Jan 27, 2017

Copy link to clipboard

Copied

Try this - as you can see, it got even more complex

var text = event.value;

if (!text) {

    text = "Your name here";

    event.value = text;

}

if (event.target.richText) {

  var spans = event.richValue;

    if (spans.length == 0) {

        text = text.split("").join(" ");

    event.value = text;

    }

    else {

  for ( var i = 0; i < spans.length; i++ )

  {

        spans.text = spans.text.split("").join(" ");

    }

    event.richValue = spans;

    }

}

else {

    text = text.split("").join(" ");

    event.value = text;

}

Votes

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
Explorer ,
Jan 27, 2017 Jan 27, 2017

Copy link to clipboard

Copied

LATEST

Amazing. I am truly grateful. That works perfectly. Thank you.

Best,

Karen

Votes

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