[英]How to change rich text without losing its format
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.
如果通过Acrobat /阅读器属性栏添加了格式,则在通过JavaScript进行更改后,您将无法复制格式。 Unfortunately, the richValue property doesn't capture all of the formatting that the Properties bar allows.
不幸的是,richValue属性无法捕获“属性”栏允许的所有格式。 You can get back the paragraphs by testing the text property of a span to see if it contains a single space.
您可以通过测试跨度的text属性来查看段落是否包含单个空格,以获取段落。 If so, add \\n\\n to the text property of the span just before it.
如果是这样,请将\\ n \\ n添加到跨度的text属性之前。 You won't be able to get back the indents.
您将无法找回缩进。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.