Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

RtfLosslessEditor

OfficeIMO.Rtf

Namespace
OfficeIMO.Rtf
Assembly
OfficeIMO.Rtf
Source revision
ba882f6b0d07 with working tree changes
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

Constructors

RtfLosslessEditor 2 overloads
public RtfLosslessEditor(RtfReadResult readResult) #

Creates a lossless editor from a read result.

Parameters

readResult OfficeIMO.Rtf.RtfReadResult required
public RtfLosslessEditor(RtfSyntaxTree syntaxTree) #

Creates a lossless editor from an RTF syntax tree.

Parameters

syntaxTree OfficeIMO.Rtf.Syntax.RtfSyntaxTree required

Methods

public void AddRevisionSaveId(int id) #

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) #

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) #

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

Parameters

index int required
text string required
public void InsertRootRtf(int index, string rtfFragment) #

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) #

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) #

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) #

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) #

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) #

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

Parameters

side OfficeIMO.Rtf.RtfPageBorderSide required
public void RemoveRevisionAuthor(int index) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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

Parameters

path string required
public void SaveLossless(Stream stream) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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

Parameters

twips int? required
public void SetDifferentFirstPageHeaderFooter(bool enabled = true) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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) #

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() #

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

Returns

byte[]
public RtfReadResult ToReadResult(RtfLoadOptions? options = null) #

Reads the edited syntax tree into a fresh semantic model.

Parameters

options OfficeIMO.Rtf.RtfLoadOptions? = null optional
public string ToRtf() #

Serializes the edited syntax tree without semantic normalization.

Returns

string

Properties

public RtfSyntaxTree SyntaxTree { get; } #

Current edited syntax tree.

public int RootNodeCount { get; } #

Number of direct syntax nodes inside the root RTF group.