Class TxtSaveOptions
Namespace: Aspose.Words.Saving
Assembly: Aspose.Words.dll (25.12.0)
Can be used to specify additional options when saving a document into the Aspose.Words.SaveFormat.Text format.
To learn more, visit the Specify Save Options documentation article.
public class TxtSaveOptions : TxtSaveOptionsBaseInheritance
object ← SaveOptions ← TxtSaveOptionsBase ← TxtSaveOptions
Inherited Members
TxtSaveOptionsBase.Encoding , TxtSaveOptionsBase.ParagraphBreak , TxtSaveOptionsBase.ForcePageBreaks , TxtSaveOptionsBase.ExportHeadersFootersMode , SaveOptions.CreateSaveOptions(SaveFormat) , SaveOptions.CreateSaveOptions(string) , SaveOptions.SaveFormat , SaveOptions.ExportGeneratorName , SaveOptions.TempFolder , SaveOptions.PrettyFormat , SaveOptions.UseAntiAliasing , SaveOptions.UseHighQualityRendering , SaveOptions.DmlRenderingMode , SaveOptions.DmlEffectsRenderingMode , SaveOptions.ImlRenderingMode , SaveOptions.DefaultTemplate , SaveOptions.UpdateFields , SaveOptions.UpdateLastSavedTimeProperty , SaveOptions.UpdateLastPrintedProperty , SaveOptions.UpdateCreatedTimeProperty , SaveOptions.MemoryOptimization , SaveOptions.UpdateAmbiguousTextFont , SaveOptions.Dml3DEffectsRenderingMode , SaveOptions.ProgressCallback , SaveOptions.AllowEmbeddingPostScriptFonts , SaveOptions.CustomTimeZoneInfo , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Examples
Shows how to save a .txt document with a custom paragraph break.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Paragraph 1.");
builder.Writeln("Paragraph 2.");
builder.Write("Paragraph 3.");
// Create a "TxtSaveOptions" object, which we can pass to the document's "Save" method
// to modify how we save the document to plaintext.
TxtSaveOptions txtSaveOptions = new TxtSaveOptions();
Assert.That(txtSaveOptions.SaveFormat, Is.EqualTo(SaveFormat.Text));
// Set the "ParagraphBreak" to a custom value that we wish to put at the end of every paragraph.
txtSaveOptions.ParagraphBreak = " End of paragraph.\n\n\t";
doc.Save(ArtifactsDir + "TxtSaveOptions.ParagraphBreak.txt", txtSaveOptions);
string docText = File.ReadAllText(ArtifactsDir + "TxtSaveOptions.ParagraphBreak.txt");
Assert.That(docText, Is.EqualTo("Paragraph 1. End of paragraph.\n\n\t" +
"Paragraph 2. End of paragraph.\n\n\t" +
"Paragraph 3. End of paragraph.\n\n\t"));Constructors
TxtSaveOptions()
public TxtSaveOptions()Properties
AddBidiMarks
Specifies whether to add bi-directional marks before each BiDi run when exporting in plain text format.
The default value is false.
public bool AddBidiMarks { get; set; }Property Value
Examples
Shows how to insert Unicode Character ‘RIGHT-TO-LEFT MARK’ (U+200F) before each bi-directional Run in text.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello world!");
builder.ParagraphFormat.Bidi = true;
builder.Writeln("שלום עולם!");
builder.Writeln("مرحبا بالعالم!");
// Create a "TxtSaveOptions" object, which we can pass to the document's "Save" method
// to modify how we save the document to plaintext.
TxtSaveOptions saveOptions = new TxtSaveOptions { Encoding = System.Text.Encoding.Unicode};
// Set the "AddBidiMarks" property to "true" to add marks before runs
// with right-to-left text to indicate the fact.
// Set the "AddBidiMarks" property to "false" to write all left-to-right
// and right-to-left run equally with nothing to indicate which is which.
saveOptions.AddBidiMarks = addBidiMarks;
doc.Save(ArtifactsDir + "TxtSaveOptions.AddBidiMarks.txt", saveOptions);
string docText = System.Text.Encoding.Unicode.GetString(File.ReadAllBytes(ArtifactsDir + "TxtSaveOptions.AddBidiMarks.txt"));
if (addBidiMarks)
{
Assert.That(docText, Is.EqualTo("\uFEFFHello world!\r\nשלום עולם!\r\nمرحبا بالعالم!\r\n\r\n"));
Assert.That(docText.Contains("\u200f"), Is.True);
}
else
{
Assert.That(docText, Is.EqualTo("\uFEFFHello world!\r\nשלום עולם!\r\nمرحبا بالعالم!\r\n\r\n"));
Assert.That(docText.Contains("\u200f"), Is.False);
}ListIndentation
Gets a Aspose.Words.Saving.TxtListIndentation object that specifies how many and which character to use for indentation of list levels. By default, it is zero count of character ‘\0’, that means no indentation.
public TxtListIndentation ListIndentation { get; }Property Value
Examples
Shows how to configure list indenting when saving a document to plaintext.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a list with three levels of indentation.
builder.ListFormat.ApplyNumberDefault();
builder.Writeln("Item 1");
builder.ListFormat.ListIndent();
builder.Writeln("Item 2");
builder.ListFormat.ListIndent();
builder.Write("Item 3");
// Create a "TxtSaveOptions" object, which we can pass to the document's "Save" method
// to modify how we save the document to plaintext.
TxtSaveOptions txtSaveOptions = new TxtSaveOptions();
// Set the "Character" property to assign a character to use
// for padding that simulates list indentation in plaintext.
txtSaveOptions.ListIndentation.Character = ' ';
// Set the "Count" property to specify the number of times
// to place the padding character for each list indent level.
txtSaveOptions.ListIndentation.Count = 3;
doc.Save(ArtifactsDir + "TxtSaveOptions.TxtListIndentation.txt", txtSaveOptions);
string docText = File.ReadAllText(ArtifactsDir + "TxtSaveOptions.TxtListIndentation.txt");
string newLine= Environment.NewLine;
Assert.That(docText, Is.EqualTo($"1. Item 1{newLine}" +
$" a. Item 2{newLine}" +
$" i. Item 3{newLine}"));MaxCharactersPerLine
Gets or sets an integer value that specifies the maximum number of characters per one line. The default value is 0, that means no limit.
public int MaxCharactersPerLine { get; set; }Property Value
Examples
Shows how to set maximum number of characters per line.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " +
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.");
// Set 30 characters as maximum allowed per one line.
TxtSaveOptions saveOptions = new TxtSaveOptions { MaxCharactersPerLine = 30 };
doc.Save(ArtifactsDir + "TxtSaveOptions.MaxCharactersPerLine.txt", saveOptions);OfficeMathExportMode
Specifies how OfficeMath will be written to the output file. Default value is Aspose.Words.Saving.TxtOfficeMathExportMode.Text.
public TxtOfficeMathExportMode OfficeMathExportMode { get; set; }Property Value
Examples
Shows how to export OfficeMath object as Latex in TXT.
Document doc = new Document(MyDir + "Office math.docx");
TxtSaveOptions saveOptions = new TxtSaveOptions();
saveOptions.OfficeMathExportMode = TxtOfficeMathExportMode.Latex;
doc.Save(ArtifactsDir + "TxtSaveOptions.ExportOfficeMathAsLatexToText.txt", saveOptions);PreserveTableLayout
Specifies whether the program should attempt to preserve layout of tables when saving in the plain text format.
The default value is false.
public bool PreserveTableLayout { get; set; }Property Value
Examples
Shows how to preserve the layout of tables when converting to plaintext.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.StartTable();
builder.InsertCell();
builder.Write("Row 1, cell 1");
builder.InsertCell();
builder.Write("Row 1, cell 2");
builder.EndRow();
builder.InsertCell();
builder.Write("Row 2, cell 1");
builder.InsertCell();
builder.Write("Row 2, cell 2");
builder.EndTable();
// Create a "TxtSaveOptions" object, which we can pass to the document's "Save" method
// to modify how we save the document to plaintext.
TxtSaveOptions txtSaveOptions = new TxtSaveOptions();
// Set the "PreserveTableLayout" property to "true" to apply whitespace padding to the contents
// of the output plaintext document to preserve as much of the table's layout as possible.
// Set the "PreserveTableLayout" property to "false" to save all tables' contents
// as a continuous body of text, with just a new line for each row.
txtSaveOptions.PreserveTableLayout = preserveTableLayout;
doc.Save(ArtifactsDir + "TxtSaveOptions.PreserveTableLayout.txt", txtSaveOptions);
string docText = File.ReadAllText(ArtifactsDir + "TxtSaveOptions.PreserveTableLayout.txt");
if (preserveTableLayout)
Assert.That(docText, Is.EqualTo("Row 1, cell 1 Row 1, cell 2\r\n" +
"Row 2, cell 1 Row 2, cell 2\r\n\r\n"));
else
Assert.That(docText, Is.EqualTo("Row 1, cell 1\r" +
"Row 1, cell 2\r" +
"Row 2, cell 1\r" +
"Row 2, cell 2\r\r\n"));SaveFormat
Specifies the format in which the document will be saved if this save options object is used. Can only be Aspose.Words.SaveFormat.Text.
public override SaveFormat SaveFormat { get; set; }Property Value
Examples
Shows how to save a .txt document with a custom paragraph break.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Paragraph 1.");
builder.Writeln("Paragraph 2.");
builder.Write("Paragraph 3.");
// Create a "TxtSaveOptions" object, which we can pass to the document's "Save" method
// to modify how we save the document to plaintext.
TxtSaveOptions txtSaveOptions = new TxtSaveOptions();
Assert.That(txtSaveOptions.SaveFormat, Is.EqualTo(SaveFormat.Text));
// Set the "ParagraphBreak" to a custom value that we wish to put at the end of every paragraph.
txtSaveOptions.ParagraphBreak = " End of paragraph.\n\n\t";
doc.Save(ArtifactsDir + "TxtSaveOptions.ParagraphBreak.txt", txtSaveOptions);
string docText = File.ReadAllText(ArtifactsDir + "TxtSaveOptions.ParagraphBreak.txt");
Assert.That(docText, Is.EqualTo("Paragraph 1. End of paragraph.\n\n\t" +
"Paragraph 2. End of paragraph.\n\n\t" +
"Paragraph 3. End of paragraph.\n\n\t"));SimplifyListLabels
Specifies whether the program should simplify list labels in case of complex label formatting not being adequately represented by plain text.
If set to true, numbered list labels are written in simple numeric format
and itemized list labels as simple ASCII characters. The default value is false.
public bool SimplifyListLabels { get; set; }Property Value
Examples
Shows how to change the appearance of lists when saving a document to plaintext.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a bulleted list with five levels of indentation.
builder.ListFormat.ApplyBulletDefault();
builder.Writeln("Item 1");
builder.ListFormat.ListIndent();
builder.Writeln("Item 2");
builder.ListFormat.ListIndent();
builder.Writeln("Item 3");
builder.ListFormat.ListIndent();
builder.Writeln("Item 4");
builder.ListFormat.ListIndent();
builder.Write("Item 5");
// Create a "TxtSaveOptions" object, which we can pass to the document's "Save" method
// to modify how we save the document to plaintext.
TxtSaveOptions txtSaveOptions = new TxtSaveOptions();
// Set the "SimplifyListLabels" property to "true" to convert some list
// symbols into simpler ASCII characters, such as '*', 'o', '+', '>', etc.
// Set the "SimplifyListLabels" property to "false" to preserve as many original list symbols as possible.
txtSaveOptions.SimplifyListLabels = simplifyListLabels;
doc.Save(ArtifactsDir + "TxtSaveOptions.SimplifyListLabels.txt", txtSaveOptions);
string docText = File.ReadAllText(ArtifactsDir + "TxtSaveOptions.SimplifyListLabels.txt");
string newLine = Environment.NewLine;
if (simplifyListLabels)
Assert.That(docText, Is.EqualTo($"* Item 1{newLine}" +
$" > Item 2{newLine}" +
$" + Item 3{newLine}" +
$" - Item 4{newLine}" +
$" o Item 5{newLine}"));
else
Assert.That(docText, Is.EqualTo($"· Item 1{newLine}" +
$"o Item 2{newLine}" +
$"§ Item 3{newLine}" +
$"· Item 4{newLine}" +
$"o Item 5{newLine}"));