Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/

API Reference

Class

RtfLosslessEditor

Namespace OfficeIMO.Rtf
Assembly OfficeIMO.Rtf
Modifiers sealed

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

Inheritance

  • Object
  • RtfLosslessEditor

Usage

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

Returned or exposed by

Constructors

RtfLosslessEditor 2 overloads
public RtfLosslessEditor(RtfReadResult readResult) #

Creates a lossless editor from a read result.

Parameters

readResult OfficeIMO.Rtf.RtfReadResult requiredposition: 0
public RtfLosslessEditor(RtfSyntaxTree syntaxTree) #

Creates a lossless editor from an RTF syntax tree.

Parameters

syntaxTree OfficeIMO.Rtf.Syntax.RtfSyntaxTree requiredposition: 0

Methods

public Void AddRevisionSaveId(Int32 id) #
Returns: Void

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

Parameters

id System.Int32 requiredposition: 0
public Void AppendParagraph(String text) #
Returns: Void

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

Parameters

text System.String requiredposition: 0
public Void InsertRootParagraph(Int32 index, String text) #
Returns: Void

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

Parameters

index System.Int32 requiredposition: 0
text System.String requiredposition: 1
public Void InsertRootRtf(Int32 index, String rtfFragment) #
Returns: Void

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

Parameters

index System.Int32 requiredposition: 0
rtfFragment System.String requiredposition: 1
public Void MoveRootNodes(Int32 fromIndex, Int32 count, Int32 toIndex) #
Returns: Void

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

Parameters

fromIndex System.Int32 requiredposition: 0
count System.Int32 requiredposition: 1
toIndex System.Int32 requiredposition: 2
public Void RemoveColor(Int32 index) #
Returns: Void

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

Parameters

index System.Int32 requiredposition: 0
public Void RemoveFileReference(Int32 id) #
Returns: Void

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

Parameters

id System.Int32 requiredposition: 0
public Void RemoveFont(Int32 id) #
Returns: Void

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

Parameters

id System.Int32 requiredposition: 0
public Void RemovePageBorder(RtfPageBorderSide side) #
Returns: Void

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

Parameters

side OfficeIMO.Rtf.RtfPageBorderSide requiredposition: 0
public Void RemoveRevisionAuthor(Int32 index) #
Returns: Void

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

Parameters

index System.Int32 requiredposition: 0
public Void RemoveRevisionSaveId(Int32 id) #
Returns: Void

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

Parameters

id System.Int32 requiredposition: 0
public Int32 RemoveRootNodes(Int32 index, Int32 count = 1) #
Returns: Int32

Removes direct root syntax nodes and returns the number removed.

Parameters

index System.Int32 requiredposition: 0
count System.Int32 = 1 optionalposition: 1
public Void RemoveStyle(Int32 id, RtfStyleKind kind = Paragraph) #
Returns: Void

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

Parameters

id System.Int32 requiredposition: 0
kind OfficeIMO.Rtf.RtfStyleKind = Paragraph optionalposition: 1
public Void RemoveUserProperty(String name) #
Returns: Void

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

Parameters

name System.String requiredposition: 0
public Void RemoveXmlNamespace(Int32 id) #
Returns: Void

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

Parameters

id System.Int32 requiredposition: 0
public Int32 ReplaceDestinationContent(String destination, String rtfFragment) #
Returns: Int32

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

Parameters

destination System.String requiredposition: 0
rtfFragment System.String requiredposition: 1
public Boolean ReplaceImage(Int32 imageIndex, RtfImage replacement) #
Returns: Boolean

Replaces the nth picture destination while preserving all unrelated syntax.

Parameters

imageIndex System.Int32 requiredposition: 0
replacement OfficeIMO.Rtf.RtfImage requiredposition: 1
public Int32 ReplaceText(String oldText, String newText, StringComparison comparison = Ordinal) #
Returns: Int32

Replaces literal visible text contained inside individual text nodes.

Parameters

oldText System.String requiredposition: 0
newText System.String requiredposition: 1
comparison System.StringComparison = Ordinal optionalposition: 2
SaveLossless 2 overloads
public Void SaveLossless(String path) #
Returns: Void

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

Parameters

path System.String requiredposition: 0
public Void SaveLossless(Stream stream) #
Returns: Void

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

Parameters

stream System.IO.Stream requiredposition: 0
SaveLosslessAsync 2 overloads
public Task SaveLosslessAsync(String path, CancellationToken cancellationToken = default) #
Returns: Task

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

Parameters

path System.String requiredposition: 0
cancellationToken System.Threading.CancellationToken = default optionalposition: 1
public Task SaveLosslessAsync(Stream stream, CancellationToken cancellationToken = default) #
Returns: Task

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

Parameters

stream System.IO.Stream requiredposition: 0
cancellationToken System.Threading.CancellationToken = default optionalposition: 1
public Void SetAnsiCodePage(Nullable<Int32> codePage) #
Returns: Void

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

Parameters

codePage System.Nullable{System.Int32} requiredposition: 0
public Void SetCharacterSet(RtfDocumentCharacterSet characterSet, Nullable<Int32> ansiCodePage = null) #
Returns: Void

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

Parameters

characterSet OfficeIMO.Rtf.RtfDocumentCharacterSet requiredposition: 0
ansiCodePage System.Nullable{System.Int32} = null optionalposition: 1
SetColor 2 overloads
public Void SetColor(Int32 index, RtfColor color) #
Returns: Void

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

Parameters

index System.Int32 requiredposition: 0
color OfficeIMO.Rtf.RtfColor requiredposition: 1
public Void SetColor(Int32 index, Byte red, Byte green, Byte blue) #
Returns: Void

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

Parameters

index System.Int32 requiredposition: 0
red System.Byte requiredposition: 1
green System.Byte requiredposition: 2
blue System.Byte requiredposition: 3
public Void SetDefaultFont(Nullable<Int32> fontId) #
Returns: Void

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

Parameters

fontId System.Nullable{System.Int32} requiredposition: 0
public Void SetDefaultLanguages(Nullable<Int32> defaultLanguageId = null, Nullable<Int32> defaultFarEastLanguageId = null, Nullable<Int32> defaultAlternateLanguageId = null) #
Returns: Void

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

Parameters

defaultLanguageId System.Nullable{System.Int32} = null optionalposition: 0
defaultFarEastLanguageId System.Nullable{System.Int32} = null optionalposition: 1
defaultAlternateLanguageId System.Nullable{System.Int32} = null optionalposition: 2
public Void SetDefaultTabWidth(Nullable<Int32> twips) #
Returns: Void

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

Parameters

twips System.Nullable{System.Int32} requiredposition: 0
public Void SetDifferentFirstPageHeaderFooter(Boolean enabled = true) #
Returns: Void

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

Parameters

enabled System.Boolean = true optionalposition: 0
public Void SetDocumentDirection(Nullable<RtfTextDirection> direction) #
Returns: Void

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

Parameters

direction System.Nullable{OfficeIMO.Rtf.RtfTextDirection} requiredposition: 0
public Void SetDocumentHyphenation(Nullable<Boolean> automatic = null, Nullable<Boolean> caps = null, Nullable<Int32> consecutiveLimit = null, Nullable<Int32> zoneTwips = null) #
Returns: Void

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

Parameters

automatic System.Nullable{System.Boolean} = null optionalposition: 0
caps System.Nullable{System.Boolean} = null optionalposition: 1
consecutiveLimit System.Nullable{System.Int32} = null optionalposition: 2
zoneTwips System.Nullable{System.Int32} = null optionalposition: 3
public Void SetDocumentLayoutOptions(Nullable<Boolean> widowOrphanControl = null, Nullable<Boolean> facingPages = null, Nullable<Boolean> mirrorMargins = null) #
Returns: Void

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

Parameters

widowOrphanControl System.Nullable{System.Boolean} = null optionalposition: 0
facingPages System.Nullable{System.Boolean} = null optionalposition: 1
mirrorMargins System.Nullable{System.Boolean} = null optionalposition: 2
public Void SetDocumentProtection(Nullable<Boolean> forms = null, Nullable<Boolean> revisions = null, Nullable<Boolean> annotations = null, Nullable<Boolean> readOnly = null) #
Returns: Void

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

Parameters

forms System.Nullable{System.Boolean} = null optionalposition: 0
revisions System.Nullable{System.Boolean} = null optionalposition: 1
annotations System.Nullable{System.Boolean} = null optionalposition: 2
readOnly System.Nullable{System.Boolean} = null optionalposition: 3
public Void SetDocumentVariable(String name, String value) #
Returns: Void

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 System.String requiredposition: 0
value System.String requiredposition: 1
public Void SetDocumentView(Nullable<Int32> kind = null, Nullable<Int32> scale = null, Nullable<Int32> zoomKind = null, Nullable<Int32> backspaceBehavior = null) #
Returns: Void

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

Parameters

kind System.Nullable{System.Int32} = null optionalposition: 0
scale System.Nullable{System.Int32} = null optionalposition: 1
zoomKind System.Nullable{System.Int32} = null optionalposition: 2
backspaceBehavior System.Nullable{System.Int32} = null optionalposition: 3
public Void SetDrawingGrid(Nullable<Int32> horizontalSpacingTwips = null, Nullable<Int32> verticalSpacingTwips = null, Nullable<Int32> horizontalOriginTwips = null, Nullable<Int32> verticalOriginTwips = null, Nullable<Int32> horizontalShow = null, Nullable<Int32> verticalShow = null, Nullable<Boolean> snapToGrid = null, Nullable<Boolean> useMargins = null) #
Returns: Void

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

Parameters

horizontalSpacingTwips System.Nullable{System.Int32} = null optionalposition: 0
verticalSpacingTwips System.Nullable{System.Int32} = null optionalposition: 1
horizontalOriginTwips System.Nullable{System.Int32} = null optionalposition: 2
verticalOriginTwips System.Nullable{System.Int32} = null optionalposition: 3
horizontalShow System.Nullable{System.Int32} = null optionalposition: 4
verticalShow System.Nullable{System.Int32} = null optionalposition: 5
snapToGrid System.Nullable{System.Boolean} = null optionalposition: 6
useMargins System.Nullable{System.Boolean} = null optionalposition: 7
SetFileReference 2 overloads
public Void SetFileReference(RtfFileReference fileReference) #
Returns: Void

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 requiredposition: 0
public Void SetFileReference(Int32 id, String path) #
Returns: Void

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

Parameters

id System.Int32 requiredposition: 0
path System.String requiredposition: 1
SetFont 2 overloads
public Void SetFont(RtfFont font) #
Returns: Void

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 requiredposition: 0
public Void SetFont(Int32 id, String name) #
Returns: Void

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

Parameters

id System.Int32 requiredposition: 0
name System.String requiredposition: 1
public Void SetGenerator(String value) #
Returns: Void

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

Parameters

value System.String requiredposition: 0
public Void SetGutterWidth(Nullable<Int32> gutterWidthTwips) #
Returns: Void

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

Parameters

gutterWidthTwips System.Nullable{System.Int32} requiredposition: 0
public Void SetHeaderFooterDistance(Nullable<Int32> headerDistanceTwips = null, Nullable<Int32> footerDistanceTwips = null) #
Returns: Void

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

Parameters

headerDistanceTwips System.Nullable{System.Int32} = null optionalposition: 0
footerDistanceTwips System.Nullable{System.Int32} = null optionalposition: 1
public Void SetInfo(RtfDocumentInfoField field, String value) #
Returns: Void

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

Parameters

field OfficeIMO.Rtf.RtfDocumentInfoField requiredposition: 0
value System.String requiredposition: 1
public Void SetInfoNumber(RtfDocumentInfoNumberField field, Nullable<Int32> value) #
Returns: Void

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

Parameters

field OfficeIMO.Rtf.RtfDocumentInfoNumberField requiredposition: 0
value System.Nullable{System.Int32} requiredposition: 1
public Void SetInfoTimestamp(RtfDocumentInfoTimestampField field, Nullable<DateTime> value) #
Returns: Void

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

Parameters

field OfficeIMO.Rtf.RtfDocumentInfoTimestampField requiredposition: 0
value System.Nullable{System.DateTime} requiredposition: 1
public Void SetLandscape(Boolean enabled = true) #
Returns: Void

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

Parameters

enabled System.Boolean = true optionalposition: 0
public Void SetMargins(Nullable<Int32> leftTwips = null, Nullable<Int32> rightTwips = null, Nullable<Int32> topTwips = null, Nullable<Int32> bottomTwips = null) #
Returns: Void

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

Parameters

leftTwips System.Nullable{System.Int32} = null optionalposition: 0
rightTwips System.Nullable{System.Int32} = null optionalposition: 1
topTwips System.Nullable{System.Int32} = null optionalposition: 2
bottomTwips System.Nullable{System.Int32} = null optionalposition: 3
public Void SetPageBorder(RtfPageBorderSide side, RtfPageBorderStyle style, Nullable<Int32> width = null, Nullable<Int32> space = null, Nullable<Int32> colorIndex = null, Boolean frame = false) #
Returns: Void

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

Parameters

side OfficeIMO.Rtf.RtfPageBorderSide requiredposition: 0
style OfficeIMO.Rtf.RtfPageBorderStyle requiredposition: 1
width System.Nullable{System.Int32} = null optionalposition: 2
space System.Nullable{System.Int32} = null optionalposition: 3
colorIndex System.Nullable{System.Int32} = null optionalposition: 4
frame System.Boolean = false optionalposition: 5
public Void SetPageBorderOptions(Nullable<Boolean> includeHeader = null, Nullable<Boolean> includeFooter = null, Nullable<Boolean> snapToPageBorder = null, Nullable<RtfPageBorderScope> scope = null, Nullable<Boolean> displayBehindText = null, Nullable<RtfPageBorderOffset> offsetFrom = null) #
Returns: Void

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

Parameters

includeHeader System.Nullable{System.Boolean} = null optionalposition: 0
includeFooter System.Nullable{System.Boolean} = null optionalposition: 1
snapToPageBorder System.Nullable{System.Boolean} = null optionalposition: 2
scope System.Nullable{OfficeIMO.Rtf.RtfPageBorderScope} = null optionalposition: 3
displayBehindText System.Nullable{System.Boolean} = null optionalposition: 4
offsetFrom System.Nullable{OfficeIMO.Rtf.RtfPageBorderOffset} = null optionalposition: 5
public Void SetPageNumbering(Nullable<Int32> start = null, Nullable<Boolean> restart = null, Nullable<RtfPageNumberFormat> format = null, Nullable<Int32> positionXTwips = null, Nullable<Int32> positionYTwips = null) #
Returns: Void

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

Parameters

start System.Nullable{System.Int32} = null optionalposition: 0
restart System.Nullable{System.Boolean} = null optionalposition: 1
format System.Nullable{OfficeIMO.Rtf.RtfPageNumberFormat} = null optionalposition: 2
positionXTwips System.Nullable{System.Int32} = null optionalposition: 3
positionYTwips System.Nullable{System.Int32} = null optionalposition: 4
public Void SetPageSize(Nullable<Int32> widthTwips, Nullable<Int32> heightTwips) #
Returns: Void

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

Parameters

widthTwips System.Nullable{System.Int32} requiredposition: 0
heightTwips System.Nullable{System.Int32} requiredposition: 1
public Void SetPrinterPaper(Nullable<Int32> paperSize = null, Nullable<Int32> firstPageSource = null, Nullable<Int32> otherPagesSource = null) #
Returns: Void

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

Parameters

paperSize System.Nullable{System.Int32} = null optionalposition: 0
firstPageSource System.Nullable{System.Int32} = null optionalposition: 1
otherPagesSource System.Nullable{System.Int32} = null optionalposition: 2
public Void SetRevisionAuthor(Int32 index, String name) #
Returns: Void

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

Parameters

index System.Int32 requiredposition: 0
name System.String requiredposition: 1
public Void SetRevisionRootSaveId(Nullable<Int32> id) #
Returns: Void

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

Parameters

id System.Nullable{System.Int32} requiredposition: 0
public Void SetRevisionTracking(Nullable<Boolean> enabled = null, Nullable<Int32> displayStyle = null, Nullable<Int32> barPlacement = null) #
Returns: Void

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

Parameters

enabled System.Nullable{System.Boolean} = null optionalposition: 0
displayStyle System.Nullable{System.Int32} = null optionalposition: 1
barPlacement System.Nullable{System.Int32} = null optionalposition: 2
public Void SetRtlGutter(Boolean enabled = true) #
Returns: Void

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

Parameters

enabled System.Boolean = true optionalposition: 0
public Void SetStyleName(Int32 id, String name, RtfStyleKind kind = Paragraph) #
Returns: Void

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

Parameters

id System.Int32 requiredposition: 0
name System.String requiredposition: 1
kind OfficeIMO.Rtf.RtfStyleKind = Paragraph optionalposition: 2
public Void SetUnicodeSkipCount(Nullable<Int32> count) #
Returns: Void

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

Parameters

count System.Nullable{System.Int32} requiredposition: 0
SetUserProperty 2 overloads
public Void SetUserProperty(RtfUserProperty property) #
Returns: Void

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 requiredposition: 0
public Void SetUserProperty(String name, String value) #
Returns: Void

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

Parameters

name System.String requiredposition: 0
value System.String requiredposition: 1
public Void SetXmlNamespace(Int32 id, String uri) #
Returns: Void

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

Parameters

id System.Int32 requiredposition: 0
uri System.String requiredposition: 1
public Byte[] ToBytesLossless() #
Returns: Byte[]

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

public RtfReadResult ToReadResult(RtfReadOptions options = null) #
Returns: RtfReadResult

Reads the edited syntax tree into a fresh semantic model.

Parameters

options OfficeIMO.Rtf.RtfReadOptions = null optionalposition: 0
public String ToRtf() #
Returns: String

Serializes the edited syntax tree without semantic normalization.

Properties

public RtfSyntaxTree SyntaxTree { get; } #

Current edited syntax tree.

public Int32 RootNodeCount { get; } #

Number of direct syntax nodes inside the root RTF group.