简体   繁体   English

如何更改格式文本而不丢失其格式

[英]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.

相关问题 如何在不丢失正确格式的情况下使用Javascript更改hidden_​​field数组? - How to change a hidden_field array using Javascript without losing its correct format? 将没有丰富 styles 的纯文本复制到剪贴板而不失去焦点? - Copy plain text with no rich styles to clipboard without losing focus? 如何在内容可编辑div中替换字符串而不丢失已经对部分文本执行的文本格式 - How to replace string without losing text format already done to a part of text in content editable div 如何使按钮在某个时间点后改变其步长而又不会失去价值? - How do I make a button change its step after some point without losing value? 我如何从网页中抓取 HTML 代码,因为它使用的是 beautifulsoup 而不丢失文本格式? - How do I scrape the HTML code from a webpage as it is using beautifulsoup without losing text format? 如何在不丢失样式的情况下复制文本? - How to copy text without losing it's style? 如何更改没有任何标签的复选框旁边的文本? - How to change text beside its checkbox without any tag? 网页中的经典富文本格式 - Classic Rich Text Format in a webpage 如何在 angular 中以正确的格式显示富文本 - How to display rich Text in it's right format in angular 如何改变<p>标记文本,不删除下划线或斜体格式? - How to change <p> tag text, without remove underline or italic format?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM