How can I change the rich text of a field without loosing its format?
When I try to do something as simple as this
var spans = this.getField("My Field").richValue
event.richValue = spans
the text becomes de-formatted: no linebreaks, no paragraphs / indention, different text size, etc.
Is there a way to copy the rich text exactly as it is? My goal would be to replace a part of the text without changing the formatting.
var spans = this.getField("My Field").richValue
for (var i = 0; i < spans.length; i++) {
spans[i].text = spans[i].text.replace(...)
}
event.richValue = spans
You probably can't. If the formatting was added through the Acrobat/Reader Properties bar, you won't be able to duplicate the formatting after a change made via JavaScript. Unfortunately, the richValue property doesn't capture all of the formatting that the Properties bar allows. You can get back the paragraphs by testing the text property of a span to see if it contains a single space. If so, add \\n\\n to the text property of the span just before it. You won't be able to get back the indents.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.