# RtfLosslessEditor

Applies targeted edits to an RTF syntax tree while preserving untouched raw RTF.

Class 

`OfficeIMO.Rtf`

**Namespace**

`OfficeIMO.Rtf`

**Assembly**

`OfficeIMO.Rtf`

**Source revision**

`ba882f6b0d07` with working tree changes

**Source**

[RtfLosslessEditor.cs:15](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L15)

**Modifiers**

sealed

Applies targeted edits to an RTF syntax tree while preserving untouched raw RTF.

## Inheritance

- object
- RtfLosslessEditor

## Usage

Explore 2 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

### Returned or exposed by 2

- Method [RtfReadResult.EditLossless](/api/rtf/officeimo-rtf-rtfreadresult/#method-editlossless)
- Method [RtfSyntaxTree.EditLossless](/api/rtf/officeimo-rtf-syntax-rtfsyntaxtree/#method-editlossless)

Filter members 

Show inherited

## Constructors

RtfLosslessEditor 2 overloads

`public RtfLosslessEditor(RtfReadResult readResult)` [#](#constructor-ctor-officeimo-rtf-rtfreadresult)

[RtfLosslessEditor.cs:15](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L15)

Creates a lossless editor from a read result.

Parameters

**readResult OfficeIMO.Rtf.RtfReadResult required**

`public RtfLosslessEditor(RtfSyntaxTree syntaxTree)` [#](#constructor-ctor-officeimo-rtf-syntax-rtfsyntaxtree)

[RtfLosslessEditor.cs:21](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L21)

Creates a lossless editor from an RTF syntax tree.

Parameters

**syntaxTree OfficeIMO.Rtf.Syntax.RtfSyntaxTree required**

## Methods

`public void AddRevisionSaveId(int id)` [#](#method-addrevisionsaveid-int32)

[RtfLosslessEditor.Revisions.cs:22](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Revisions.cs#L22)

Adds a revision save id to the root rsidtbl destination, replacing duplicate entries with a single occurrence.

Parameters

**id int required**

`public void AppendParagraph(string text)` [#](#method-appendparagraph-string)

[RtfLosslessEditor.cs:98](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L98)

Appends a plain RTF paragraph at the end of the root document group while preserving existing syntax.

Parameters

**text string required**

`public void InsertRootParagraph(int index, string text)` [#](#method-insertrootparagraph-int32-string)

[RtfLosslessEditor.Structure.cs:24](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Structure.cs#L24)

Inserts a plain paragraph at a direct root-node index.

Parameters

**index int required**

**text string required**

`public void InsertRootRtf(int index, string rtfFragment)` [#](#method-insertrootrtf-int32-string)

[RtfLosslessEditor.Structure.cs:13](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Structure.cs#L13)

Inserts a validated raw RTF fragment at a direct root-node index.

Parameters

**index int required**

**rtfFragment string required**

`public void MoveRootNodes(int fromIndex, int count, int toIndex)` [#](#method-moverootnodes-int32-int32-int32)

[RtfLosslessEditor.Structure.cs:50](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Structure.cs#L50)

Moves direct root syntax nodes to their final root-node index.

Parameters

**fromIndex int required**

**count int required**

**toIndex int required**

`public void RemoveColor(int index)` [#](#method-removecolor-int32)

[RtfLosslessEditor.Colors.cs:31](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Colors.cs#L31)

Removes the one-based color-table entry when it exists while preserving the rest of the RTF stream.

Parameters

**index int required**

`public void RemoveFileReference(int id)` [#](#method-removefilereference-int32)

[RtfLosslessEditor.Files.cs:31](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Files.cs#L31)

Removes all file-table references with the supplied identifier while preserving the rest of the RTF stream.

Parameters

**id int required**

`public void RemoveFont(int id)` [#](#method-removefont-int32)

[RtfLosslessEditor.Fonts.cs:31](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Fonts.cs#L31)

Removes all font-table entries with the supplied RTF font identifier while preserving the rest of the RTF stream.

Parameters

**id int required**

`public void RemovePageBorder(RtfPageBorderSide side)` [#](#method-removepageborder-officeimo-rtf-rtfpageborderside)

[RtfLosslessEditor.PageBorders.cs:50](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.PageBorders.cs#L50)

Removes one root page-border side while preserving untouched RTF syntax.

Parameters

**side OfficeIMO.Rtf.RtfPageBorderSide required**

`public void RemoveRevisionAuthor(int index)` [#](#method-removerevisionauthor-int32)

[RtfLosslessEditor.RevisionAuthors.cs:24](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.RevisionAuthors.cs#L24)

Removes the zero-based revision author table entry when it exists while preserving the rest of the RTF stream.

Parameters

**index int required**

`public void RemoveRevisionSaveId(int id)` [#](#method-removerevisionsaveid-int32)

[RtfLosslessEditor.Revisions.cs:34](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Revisions.cs#L34)

Removes all matching revision save ids from the root rsidtbl destination while preserving the rest of the RTF stream.

Parameters

**id int required**

`public int RemoveRootNodes(int index, int count = 1)` [#](#method-removerootnodes-int32-int32)

[RtfLosslessEditor.Structure.cs:38](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Structure.cs#L38)

Removes direct root syntax nodes and returns the number removed.

Parameters

**index int required**

**count int = 1 optional**

Returns

`int`

`public void RemoveStyle(int id, RtfStyleKind kind = Paragraph)` [#](#method-removestyle-int32-officeimo-rtf-rtfstylekind)

[RtfLosslessEditor.Styles.cs:24](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Styles.cs#L24)

Removes all stylesheet entries matching the supplied id and kind while preserving the rest of the RTF stream.

Parameters

**id int required**

**kind OfficeIMO.Rtf.RtfStyleKind = Paragraph optional**

`public void RemoveUserProperty(string name)` [#](#method-removeuserproperty-string)

[RtfLosslessEditor.cs:88](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L88)

Removes all custom document properties with the supplied name while preserving the rest of the RTF stream.

Parameters

**name string required**

`public void RemoveXmlNamespace(int id)` [#](#method-removexmlnamespace-int32)

[RtfLosslessEditor.XmlNamespaces.cs:22](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.XmlNamespaces.cs#L22)

Removes all XML namespace declarations with the supplied id while preserving the rest of the RTF stream.

Parameters

**id int required**

`public int ReplaceDestinationContent(string destination, string rtfFragment)` [#](#method-replacedestinationcontent-string-string)

[RtfLosslessEditor.Structure.cs:81](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Structure.cs#L81)

Replaces the content of every matching destination group, including headers and footers.

Parameters

**destination string required**

**rtfFragment string required**

Returns

`int`

`public bool ReplaceImage(int imageIndex, RtfImage replacement)` [#](#method-replaceimage-int32-officeimo-rtf-rtfimage)

[RtfLosslessEditor.Structure.cs:65](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Structure.cs#L65)

Replaces the nth picture destination while preserving all unrelated syntax.

Parameters

**imageIndex int required**

**replacement OfficeIMO.Rtf.RtfImage required**

Returns

`bool`

`public int ReplaceText(string oldText, string newText, StringComparison comparison = Ordinal)` [#](#method-replacetext-string-string-stringcomparison)

[RtfLosslessEditor.cs:35](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L35)

Replaces literal visible text contained inside individual text nodes.

Parameters

**oldText string required**

**newText string required**

**comparison System.StringComparison = Ordinal optional**

Returns

`int`

SaveLossless 2 overloads

`public void SaveLossless(string path)` [#](#method-savelossless-string)

[RtfLosslessEditor.cs:123](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L123)

Saves the edited syntax tree to a file without semantic normalization.

Parameters

**path string required**

`public void SaveLossless(Stream stream)` [#](#method-savelossless-io-stream)

[RtfLosslessEditor.cs:131](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L131)

Saves the edited syntax tree to a stream without semantic normalization.

Parameters

**stream System.IO.Stream required**

SaveLosslessAsync 2 overloads

`public Task SaveLosslessAsync(string path, CancellationToken cancellationToken = default)` [#](#method-savelosslessasync-string-threading-cancellationtoken)

[RtfLosslessEditor.Async.cs:11](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Async.cs#L11)

Saves the edited syntax tree to a file without semantic normalization.

Parameters

**path string required**

**cancellationToken System.Threading.CancellationToken = default optional**

Returns

`Task`

`public Task SaveLosslessAsync(Stream stream, CancellationToken cancellationToken = default)` [#](#method-savelosslessasync-io-stream-threading-cancellationtoken)

[RtfLosslessEditor.Async.cs:19](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Async.cs#L19)

Saves the edited syntax tree to a stream without semantic normalization.

Parameters

**stream System.IO.Stream required**

**cancellationToken System.Threading.CancellationToken = default optional**

Returns

`Task`

`public void SetAnsiCodePage(int? codePage)` [#](#method-setansicodepage-nullable-system-int32)

[RtfLosslessEditor.Settings.cs:22](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Settings.cs#L22)

Adds, replaces, or removes the root ANSI code page control while preserving the rest of the RTF stream.

Parameters

**codePage int? required**

`public void SetCharacterSet(RtfDocumentCharacterSet characterSet, int? ansiCodePage = null)` [#](#method-setcharacterset-officeimo-rtf-rtfdocumentcharacterset-nullable-system-int32)

[RtfLosslessEditor.Settings.cs:10](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Settings.cs#L10)

Sets the root document character set declaration and optionally replaces the root ANSI code page.

Parameters

**characterSet OfficeIMO.Rtf.RtfDocumentCharacterSet required**

**ansiCodePage int? = null optional**

SetColor 2 overloads

`public void SetColor(int index, RtfColor color)` [#](#method-setcolor-int32-officeimo-rtf-rtfcolor)

[RtfLosslessEditor.Colors.cs:10](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Colors.cs#L10)

Adds or replaces a one-based color-table entry while preserving the rest of the RTF stream.

Parameters

**index int required**

**color OfficeIMO.Rtf.RtfColor required**

`public void SetColor(int index, byte red, byte green, byte blue)` [#](#method-setcolor-int32-byte-byte-byte)

[RtfLosslessEditor.Colors.cs:24](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Colors.cs#L24)

Adds or replaces a one-based RGB color-table entry while preserving the rest of the RTF stream.

Parameters

**index int required**

**red byte required**

**green byte required**

**blue byte required**

`public void SetDefaultFont(int? fontId)` [#](#method-setdefaultfont-nullable-system-int32)

[RtfLosslessEditor.Settings.cs:32](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Settings.cs#L32)

Adds, replaces, or removes the root default font id control while preserving the rest of the RTF stream.

Parameters

**fontId int? required**

`public void SetDefaultLanguages(int? defaultLanguageId = null, int? defaultFarEastLanguageId = null, int? defaultAlternateLanguageId = null)` [#](#method-setdefaultlanguages-nullable-system-int32-nullable-system-int32-nullable-system-int32)

[RtfLosslessEditor.DocumentSettings.cs:20](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.DocumentSettings.cs#L20)

Adds, replaces, or removes root default language controls while preserving untouched RTF syntax.

Parameters

**defaultLanguageId int? = null optional**

**defaultFarEastLanguageId int? = null optional**

**defaultAlternateLanguageId int? = null optional**

`public void SetDefaultTabWidth(int? twips)` [#](#method-setdefaulttabwidth-nullable-system-int32)

[RtfLosslessEditor.DocumentSettings.cs:10](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.DocumentSettings.cs#L10)

Adds, replaces, or removes the root default tab width while preserving untouched RTF syntax.

Parameters

**twips int? required**

`public void SetDifferentFirstPageHeaderFooter(bool enabled = true)` [#](#method-setdifferentfirstpageheaderfooter-boolean)

[RtfLosslessEditor.PageSetup.cs:82](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.PageSetup.cs#L82)

Adds or removes the root different-first-page header/footer control while preserving untouched RTF syntax.

Parameters

**enabled bool = true optional**

`public void SetDocumentDirection(RtfTextDirection? direction)` [#](#method-setdocumentdirection-nullable-officeimo-rtf-rtftextdirection)

[RtfLosslessEditor.DocumentSettings.cs:128](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.DocumentSettings.cs#L128)

Adds, replaces, or removes the root document direction control while preserving untouched RTF syntax.

Parameters

**direction OfficeIMO.Rtf.RtfTextDirection? required**

`public void SetDocumentHyphenation(bool? automatic = null, bool? caps = null, int? consecutiveLimit = null, int? zoneTwips = null)` [#](#method-setdocumenthyphenation-nullable-system-boolean-nullable-system-boolean-nullable-system-int32-nullable-system-int32)

[RtfLosslessEditor.DocumentSettings.cs:60](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.DocumentSettings.cs#L60)

Adds, replaces, or removes root document hyphenation controls while preserving untouched RTF syntax.

Parameters

**automatic bool? = null optional**

**caps bool? = null optional**

**consecutiveLimit int? = null optional**

**zoneTwips int? = null optional**

`public void SetDocumentLayoutOptions(bool? widowOrphanControl = null, bool? facingPages = null, bool? mirrorMargins = null)` [#](#method-setdocumentlayoutoptions-nullable-system-boolean-nullable-system-boolean-nullable-system-boolean)

[RtfLosslessEditor.DocumentSettings.cs:50](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.DocumentSettings.cs#L50)

Adds, replaces, or removes root document layout option controls while preserving untouched RTF syntax.

Parameters

**widowOrphanControl bool? = null optional**

**facingPages bool? = null optional**

**mirrorMargins bool? = null optional**

`public void SetDocumentProtection(bool? forms = null, bool? revisions = null, bool? annotations = null, bool? readOnly = null)` [#](#method-setdocumentprotection-nullable-system-boolean-nullable-system-boolean-nullable-system-boolean-nullable-system-boolean)

[RtfLosslessEditor.DocumentSettings.cs:74](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.DocumentSettings.cs#L74)

Adds, replaces, or removes root document protection controls while preserving untouched RTF syntax.

Parameters

**forms bool? = null optional**

**revisions bool? = null optional**

**annotations bool? = null optional**

**readOnly bool? = null optional**

`public void SetDocumentVariable(string name, string? value)` [#](#method-setdocumentvariable-string-string)

[RtfLosslessEditor.cs:61](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L61)

Adds, replaces, or removes a root document variable while preserving the rest of the RTF stream. Pass null for value to remove all variables with the supplied name.

Parameters

**name string required**

**value string? required**

`public void SetDocumentView(int? kind = null, int? scale = null, int? zoomKind = null, int? backspaceBehavior = null)` [#](#method-setdocumentview-nullable-system-int32-nullable-system-int32-nullable-system-int32-nullable-system-int32)

[RtfLosslessEditor.DocumentSettings.cs:34](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.DocumentSettings.cs#L34)

Adds, replaces, or removes root document view controls while preserving untouched RTF syntax.

Parameters

**kind int? = null optional**

**scale int? = null optional**

**zoomKind int? = null optional**

**backspaceBehavior int? = null optional**

`public void SetDrawingGrid(int? horizontalSpacingTwips = null, int? verticalSpacingTwips = null, int? horizontalOriginTwips = null, int? verticalOriginTwips = null, int? horizontalShow = null, int? verticalShow = null, bool? snapToGrid = null, bool? useMargins = null)` [#](#member-3614892d15f9d996c718dee4)

[RtfLosslessEditor.DocumentSettings.cs:106](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.DocumentSettings.cs#L106)

Adds, replaces, or removes root drawing grid controls while preserving untouched RTF syntax.

Parameters

**horizontalSpacingTwips int? = null optional**

**verticalSpacingTwips int? = null optional**

**horizontalOriginTwips int? = null optional**

**verticalOriginTwips int? = null optional**

**horizontalShow int? = null optional**

**verticalShow int? = null optional**

**snapToGrid bool? = null optional**

**useMargins bool? = null optional**

SetFileReference 2 overloads

`public void SetFileReference(RtfFileReference fileReference)` [#](#method-setfilereference-officeimo-rtf-rtffilereference)

[RtfLosslessEditor.Files.cs:10](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Files.cs#L10)

Adds or replaces a file-table reference in the root filetbl destination while preserving the rest of the RTF stream.

Parameters

**fileReference OfficeIMO.Rtf.RtfFileReference required**

`public void SetFileReference(int id, string path)` [#](#method-setfilereference-int32-string)

[RtfLosslessEditor.Files.cs:24](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Files.cs#L24)

Adds or replaces a file-table reference with the supplied identifier and path.

Parameters

**id int required**

**path string required**

SetFont 2 overloads

`public void SetFont(RtfFont font)` [#](#method-setfont-officeimo-rtf-rtffont)

[RtfLosslessEditor.Fonts.cs:10](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Fonts.cs#L10)

Adds or replaces a font-table entry by its RTF font identifier while preserving the rest of the RTF stream.

Parameters

**font OfficeIMO.Rtf.RtfFont required**

`public void SetFont(int id, string name)` [#](#method-setfont-int32-string)

[RtfLosslessEditor.Fonts.cs:24](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Fonts.cs#L24)

Adds or replaces a font-table entry by its RTF font identifier and display name.

Parameters

**id int required**

**name string required**

`public void SetGenerator(string? value)` [#](#method-setgenerator-string)

[RtfLosslessEditor.Info.cs:10](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Info.cs#L10)

Adds, replaces, or removes the root generator metadata group while preserving the rest of the RTF stream.

Parameters

**value string? required**

`public void SetGutterWidth(int? gutterWidthTwips)` [#](#method-setgutterwidth-nullable-system-int32)

[RtfLosslessEditor.PageSetup.cs:52](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.PageSetup.cs#L52)

Adds, replaces, or removes the root document gutter width while preserving untouched RTF syntax.

Parameters

**gutterWidthTwips int? required**

`public void SetHeaderFooterDistance(int? headerDistanceTwips = null, int? footerDistanceTwips = null)` [#](#method-setheaderfooterdistance-nullable-system-int32-nullable-system-int32)

[RtfLosslessEditor.PageSetup.cs:62](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.PageSetup.cs#L62)

Adds, replaces, or removes root header and footer distance controls while preserving untouched RTF syntax.

Parameters

**headerDistanceTwips int? = null optional**

**footerDistanceTwips int? = null optional**

`public void SetInfo(RtfDocumentInfoField field, string? value)` [#](#method-setinfo-officeimo-rtf-rtfdocumentinfofield-string)

[RtfLosslessEditor.Info.cs:18](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Info.cs#L18)

Adds, replaces, or removes a document information field while preserving the rest of the RTF stream.

Parameters

**field OfficeIMO.Rtf.RtfDocumentInfoField required**

**value string? required**

`public void SetInfoNumber(RtfDocumentInfoNumberField field, int? value)` [#](#method-setinfonumber-officeimo-rtf-rtfdocumentinfonumberfield-nullable-system-int32)

[RtfLosslessEditor.Info.cs:36](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Info.cs#L36)

Adds, replaces, or removes a numeric document information field while preserving the rest of the RTF stream.

Parameters

**field OfficeIMO.Rtf.RtfDocumentInfoNumberField required**

**value int? required**

`public void SetInfoTimestamp(RtfDocumentInfoTimestampField field, DateTime? value)` [#](#method-setinfotimestamp-officeimo-rtf-rtfdocumentinfotimestampfield-nullable-system-datetime)

[RtfLosslessEditor.Info.cs:27](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Info.cs#L27)

Adds, replaces, or removes a document information timestamp while preserving the rest of the RTF stream.

Parameters

**field OfficeIMO.Rtf.RtfDocumentInfoTimestampField required**

**value System.DateTime? required**

`public void SetLandscape(bool enabled = true)` [#](#method-setlandscape-boolean)

[RtfLosslessEditor.PageSetup.cs:74](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.PageSetup.cs#L74)

Adds or removes the root landscape orientation control while preserving untouched RTF syntax.

Parameters

**enabled bool = true optional**

`public void SetMargins(int? leftTwips = null, int? rightTwips = null, int? topTwips = null, int? bottomTwips = null)` [#](#method-setmargins-nullable-system-int32-nullable-system-int32-nullable-system-int32-nullable-system-int32)

[RtfLosslessEditor.PageSetup.cs:36](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.PageSetup.cs#L36)

Adds, replaces, or removes root document margin controls while preserving untouched RTF syntax.

Parameters

**leftTwips int? = null optional**

**rightTwips int? = null optional**

**topTwips int? = null optional**

**bottomTwips int? = null optional**

`public void SetPageBorder(RtfPageBorderSide side, RtfPageBorderStyle style, int? width = null, int? space = null, int? colorIndex = null, bool frame = false)` [#](#method-setpageborder-officeimo-rtf-rtfpageborderside-officeimo-rtf-rtfpageborderstyle-nullable-system-int32-nullable-system-int32-nullable-system-int32-boolean)

[RtfLosslessEditor.PageBorders.cs:36](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.PageBorders.cs#L36)

Adds, replaces, or removes one root page-border side while preserving untouched RTF syntax.

Parameters

**side OfficeIMO.Rtf.RtfPageBorderSide required**

**style OfficeIMO.Rtf.RtfPageBorderStyle required**

**width int? = null optional**

**space int? = null optional**

**colorIndex int? = null optional**

**frame bool = false optional**

`public void SetPageBorderOptions(bool? includeHeader = null, bool? includeFooter = null, bool? snapToPageBorder = null, RtfPageBorderScope? scope = null, bool? displayBehindText = null, RtfPageBorderOffset? offsetFrom = null)` [#](#member-9f054a3749c1ba408740bb15)

[RtfLosslessEditor.PageBorders.cs:16](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.PageBorders.cs#L16)

Adds, replaces, or removes root page-border option controls while preserving untouched RTF syntax.

Parameters

**includeHeader bool? = null optional**

**includeFooter bool? = null optional**

**snapToPageBorder bool? = null optional**

**scope OfficeIMO.Rtf.RtfPageBorderScope? = null optional**

**displayBehindText bool? = null optional**

**offsetFrom OfficeIMO.Rtf.RtfPageBorderOffset? = null optional**

`public void SetPageNumbering(int? start = null, bool? restart = null, RtfPageNumberFormat? format = null, int? positionXTwips = null, int? positionYTwips = null)` [#](#method-setpagenumbering-nullable-system-int32-nullable-system-boolean-nullable-officeimo-rtf-rtfpagenumberformat-nullable-system-int32-nullable-system-int32)

[RtfLosslessEditor.PageNumbering.cs:15](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.PageNumbering.cs#L15)

Adds, replaces, or removes root page-numbering controls while preserving untouched RTF syntax.

Parameters

**start int? = null optional**

**restart bool? = null optional**

**format OfficeIMO.Rtf.RtfPageNumberFormat? = null optional**

**positionXTwips int? = null optional**

**positionYTwips int? = null optional**

`public void SetPageSize(int? widthTwips, int? heightTwips)` [#](#method-setpagesize-nullable-system-int32-nullable-system-int32)

[RtfLosslessEditor.PageSetup.cs:10](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.PageSetup.cs#L10)

Adds, replaces, or removes root document paper size controls while preserving untouched RTF syntax.

Parameters

**widthTwips int? required**

**heightTwips int? required**

`public void SetPrinterPaper(int? paperSize = null, int? firstPageSource = null, int? otherPagesSource = null)` [#](#method-setprinterpaper-nullable-system-int32-nullable-system-int32-nullable-system-int32)

[RtfLosslessEditor.PageSetup.cs:22](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.PageSetup.cs#L22)

Adds, replaces, or removes root printer paper metadata controls while preserving untouched RTF syntax.

Parameters

**paperSize int? = null optional**

**firstPageSource int? = null optional**

**otherPagesSource int? = null optional**

`public void SetRevisionAuthor(int index, string name)` [#](#method-setrevisionauthor-int32-string)

[RtfLosslessEditor.RevisionAuthors.cs:10](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.RevisionAuthors.cs#L10)

Adds or replaces a zero-based revision author table entry while preserving the rest of the RTF stream.

Parameters

**index int required**

**name string required**

`public void SetRevisionRootSaveId(int? id)` [#](#method-setrevisionrootsaveid-nullable-system-int32)

[RtfLosslessEditor.Revisions.cs:10](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Revisions.cs#L10)

Adds, replaces, or removes the root revision save id in the root rsidtbl destination while preserving the rest of the RTF stream.

Parameters

**id int? required**

`public void SetRevisionTracking(bool? enabled = null, int? displayStyle = null, int? barPlacement = null)` [#](#method-setrevisiontracking-nullable-system-boolean-nullable-system-int32-nullable-system-int32)

[RtfLosslessEditor.DocumentSettings.cs:85](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.DocumentSettings.cs#L85)

Adds, replaces, or removes root revision tracking controls while preserving untouched RTF syntax.

Parameters

**enabled bool? = null optional**

**displayStyle int? = null optional**

**barPlacement int? = null optional**

`public void SetRtlGutter(bool enabled = true)` [#](#method-setrtlgutter-boolean)

[RtfLosslessEditor.PageSetup.cs:90](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.PageSetup.cs#L90)

Adds or removes the root right-to-left gutter control while preserving untouched RTF syntax.

Parameters

**enabled bool = true optional**

`public void SetStyleName(int id, string name, RtfStyleKind kind = Paragraph)` [#](#method-setstylename-int32-string-officeimo-rtf-rtfstylekind)

[RtfLosslessEditor.Styles.cs:10](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Styles.cs#L10)

Adds a basic stylesheet entry or renames an existing entry while preserving the existing style formatting controls.

Parameters

**id int required**

**name string required**

**kind OfficeIMO.Rtf.RtfStyleKind = Paragraph optional**

`public void SetUnicodeSkipCount(int? count)` [#](#method-setunicodeskipcount-nullable-system-int32)

[RtfLosslessEditor.Settings.cs:42](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Settings.cs#L42)

Adds, replaces, or removes the root Unicode fallback skip count while preserving the rest of the RTF stream.

Parameters

**count int? required**

SetUserProperty 2 overloads

`public void SetUserProperty(RtfUserProperty property)` [#](#method-setuserproperty-officeimo-rtf-rtfuserproperty)

[RtfLosslessEditor.cs:71](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L71)

Adds or replaces a custom document property in the root userprops destination while preserving the rest of the RTF stream.

Parameters

**property OfficeIMO.Rtf.RtfUserProperty required**

`public void SetUserProperty(string name, string value)` [#](#method-setuserproperty-string-string)

[RtfLosslessEditor.cs:81](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L81)

Adds or replaces a text custom document property in the root userprops destination.

Parameters

**name string required**

**value string required**

`public void SetXmlNamespace(int id, string? uri)` [#](#method-setxmlnamespace-int32-string)

[RtfLosslessEditor.XmlNamespaces.cs:10](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.XmlNamespaces.cs#L10)

Adds, replaces, or removes an XML namespace declaration in the root xmlnstbl destination while preserving the rest of the RTF stream.

Parameters

**id int required**

**uri string? required**

`public byte[] ToBytesLossless()` [#](#method-tobyteslossless)

[RtfLosslessEditor.cs:117](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L117)

Serializes the edited syntax tree to source-preserving bytes without semantic normalization.

Returns

`byte[]`

`public RtfReadResult ToReadResult(RtfLoadOptions? options = null)` [#](#method-toreadresult-officeimo-rtf-rtfloadoptions)

[RtfLosslessEditor.cs:138](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L138)

Reads the edited syntax tree into a fresh semantic model.

Parameters

**options OfficeIMO.Rtf.RtfLoadOptions? = null optional**

Returns

`RtfReadResult`

`public string ToRtf()` [#](#method-tortf)

[RtfLosslessEditor.cs:112](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L112)

Serializes the edited syntax tree without semantic normalization.

Returns

`string`

## Inherited Methods

`public virtual bool Equals(object? obj)` [#](#method-equals-object)

Inherited from object

Parameters

**obj object? required**

Returns

`bool`

`public virtual int GetHashCode()` [#](#method-gethashcode)

Inherited from object

Returns

`int`

`public Type GetType()` [#](#method-gettype)

Inherited from object

Returns

`Type`

`public virtual string? ToString()` [#](#method-tostring)

Inherited from object

Returns

`string?`

## Properties

`public RtfSyntaxTree SyntaxTree { get; }` [#](#property-syntaxtree)

[RtfLosslessEditor.cs:26](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.cs#L26)

Current edited syntax tree.

`public int RootNodeCount { get; }` [#](#property-rootnodecount)

[RtfLosslessEditor.Structure.cs:9](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Rtf/Editing/RtfLosslessEditor.Structure.cs#L9)

Number of direct syntax nodes inside the root RTF group.

<!-- PowerForge markdown artifact sha256:EAE461C2A05B7D04661CE1AFE12012535138188C832CD01D1BCC6449C80CEFA4 -->
