public class TxtSaveOptions extends TxtSaveOptionsBase
SaveFormat.TEXT format.
To learn more, visit the Specify Save Options documentation article.
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.assertEquals(SaveFormat.TEXT, txtSaveOptions.getSaveFormat());
// Set the "ParagraphBreak" to a custom value that we wish to put at the end of every paragraph.
txtSaveOptions.setParagraphBreak(" End of paragraph.\r\r\t");
doc.save(getArtifactsDir() + "TxtSaveOptions.ParagraphBreak.txt", txtSaveOptions);
String docText = new Document(getArtifactsDir() + "TxtSaveOptions.ParagraphBreak.txt").getText().trim();
Assert.assertEquals("Paragraph 1. End of paragraph.\r\r\t" +
"Paragraph 2. End of paragraph.\r\r\t" +
"Paragraph 3. End of paragraph.", docText);
| Modifier and Type | Method and Description |
|---|---|
boolean |
getAddBidiMarks()
Specifies whether to add bi-directional marks before each BiDi run when exporting in plain text format.
|
TxtListIndentation |
getListIndentation()
Gets a
TxtListIndentation object that specifies how many and which character to use for indentation of list levels. |
int |
getMaxCharactersPerLine()
Gets an integer value that specifies the maximum number of characters per one line.
|
int |
getOfficeMathExportMode()
Specifies how OfficeMath will be written to the output file.
|
boolean |
getPreserveTableLayout()
Specifies whether the program should attempt to preserve layout of tables when saving in the plain text format.
|
int |
getSaveFormat()
Specifies the format in which the document will be saved if this save options object is used.
|
boolean |
getSimplifyListLabels()
Specifies whether the program should simplify list labels in case of complex label formatting not being adequately represented by plain text.
|
void |
setAddBidiMarks(boolean value)
Specifies whether to add bi-directional marks before each BiDi run when exporting in plain text format.
|
void |
setMaxCharactersPerLine(int value)
Sets an integer value that specifies the maximum number of characters per one line.
|
void |
setOfficeMathExportMode(int value)
Specifies how OfficeMath will be written to the output file.
|
void |
setPreserveTableLayout(boolean value)
Specifies whether the program should attempt to preserve layout of tables when saving in the plain text format.
|
void |
setSaveFormat(int value)
Specifies the format in which the document will be saved if this save options object is used.
|
void |
setSimplifyListLabels(boolean value)
Specifies whether the program should simplify list labels in case of complex label formatting not being adequately represented by plain text.
|
getEncoding, getExportHeadersFootersMode, getForcePageBreaks, getParagraphBreak, setEncoding, setExportHeadersFootersMode, setForcePageBreaks, setParagraphBreakcreateSaveOptions, createSaveOptions, getAllowEmbeddingPostScriptFonts, getCustomTimeZoneInfo, getDefaultTemplate, getDml3DEffectsRenderingMode, getDmlEffectsRenderingMode, getDmlRenderingMode, getExportGeneratorName, getImlRenderingMode, getMemoryOptimization, getPrettyFormat, getProgressCallback, getTempFolder, getUpdateAmbiguousTextFont, getUpdateCreatedTimeProperty, getUpdateFields, getUpdateLastPrintedProperty, getUpdateLastSavedTimeProperty, getUseAntiAliasing, getUseHighQualityRendering, setAllowEmbeddingPostScriptFonts, setCustomTimeZoneInfo, setDefaultTemplate, setDml3DEffectsRenderingMode, setDmlEffectsRenderingMode, setDmlRenderingMode, setExportGeneratorName, setImlRenderingMode, setMemoryOptimization, setPrettyFormat, setProgressCallback, setTempFolder, setUpdateAmbiguousTextFont, setUpdateCreatedTimeProperty, setUpdateFields, setUpdateLastPrintedProperty, setUpdateLastSavedTimeProperty, setUseAntiAliasing, setUseHighQualityRenderingpublic int getSaveFormat()
SaveFormat.TEXT.
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.assertEquals(SaveFormat.TEXT, txtSaveOptions.getSaveFormat());
// Set the "ParagraphBreak" to a custom value that we wish to put at the end of every paragraph.
txtSaveOptions.setParagraphBreak(" End of paragraph.\r\r\t");
doc.save(getArtifactsDir() + "TxtSaveOptions.ParagraphBreak.txt", txtSaveOptions);
String docText = new Document(getArtifactsDir() + "TxtSaveOptions.ParagraphBreak.txt").getText().trim();
Assert.assertEquals("Paragraph 1. End of paragraph.\r\r\t" +
"Paragraph 2. End of paragraph.\r\r\t" +
"Paragraph 3. End of paragraph.", docText);
getSaveFormat in class SaveOptionsint value. The returned value is one of SaveFormat constants.public void setSaveFormat(int value)
SaveFormat.TEXT.
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.assertEquals(SaveFormat.TEXT, txtSaveOptions.getSaveFormat());
// Set the "ParagraphBreak" to a custom value that we wish to put at the end of every paragraph.
txtSaveOptions.setParagraphBreak(" End of paragraph.\r\r\t");
doc.save(getArtifactsDir() + "TxtSaveOptions.ParagraphBreak.txt", txtSaveOptions);
String docText = new Document(getArtifactsDir() + "TxtSaveOptions.ParagraphBreak.txt").getText().trim();
Assert.assertEquals("Paragraph 1. End of paragraph.\r\r\t" +
"Paragraph 2. End of paragraph.\r\r\t" +
"Paragraph 3. End of paragraph.", docText);
setSaveFormat in class SaveOptionsvalue - The corresponding int value. The value must be one of SaveFormat constants.public boolean getSimplifyListLabels()
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.
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.getListFormat().applyBulletDefault();
builder.writeln("Item 1");
builder.getListFormat().listIndent();
builder.writeln("Item 2");
builder.getListFormat().listIndent();
builder.writeln("Item 3");
builder.getListFormat().listIndent();
builder.writeln("Item 4");
builder.getListFormat().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.setSimplifyListLabels(simplifyListLabels);
doc.save(getArtifactsDir() + "TxtSaveOptions.SimplifyListLabels.txt", txtSaveOptions);
String docText = getArtifactsDir() + "TxtSaveOptions.SimplifyListLabels.txt";
if (simplifyListLabels)
TestUtil.fileContainsString("* Item 1\r\n" +
" > Item 2\r\n" +
" + Item 3\r\n" +
" - Item 4\r\n" +
" o Item 5", docText);
else
TestUtil.fileContainsString("· Item 1\r\n" +
"o Item 2\r\n" +
"§ Item 3\r\n" +
"· Item 4\r\n" +
"o Item 5", docText);
boolean value.public void setSimplifyListLabels(boolean value)
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.
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.getListFormat().applyBulletDefault();
builder.writeln("Item 1");
builder.getListFormat().listIndent();
builder.writeln("Item 2");
builder.getListFormat().listIndent();
builder.writeln("Item 3");
builder.getListFormat().listIndent();
builder.writeln("Item 4");
builder.getListFormat().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.setSimplifyListLabels(simplifyListLabels);
doc.save(getArtifactsDir() + "TxtSaveOptions.SimplifyListLabels.txt", txtSaveOptions);
String docText = getArtifactsDir() + "TxtSaveOptions.SimplifyListLabels.txt";
if (simplifyListLabels)
TestUtil.fileContainsString("* Item 1\r\n" +
" > Item 2\r\n" +
" + Item 3\r\n" +
" - Item 4\r\n" +
" o Item 5", docText);
else
TestUtil.fileContainsString("· Item 1\r\n" +
"o Item 2\r\n" +
"§ Item 3\r\n" +
"· Item 4\r\n" +
"o Item 5", docText);
value - The corresponding boolean value.public boolean getAddBidiMarks()
Specifies whether to add bi-directional marks before each BiDi run when exporting in plain text format.
The default value is false.
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.getParagraphFormat().setBidi(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();
saveOptions.setEncoding(StandardCharsets.UTF_16);
// 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.setAddBidiMarks(addBidiMarks);
doc.save(getArtifactsDir() + "TxtSaveOptions.AddBidiMarks.txt", saveOptions);
String docText = new String(Files.readAllBytes(Paths.get(getArtifactsDir() + "TxtSaveOptions.AddBidiMarks.txt")), StandardCharsets.UTF_16);
if (addBidiMarks) {
Assert.assertEquals("Hello world!\r\nשלום עולם!\r\nمرحبا بالعالم!", docText.trim());
Assert.assertTrue(docText.contains(""));
} else {
Assert.assertEquals("Hello world!\r\nשלום עולם!\r\nمرحبا بالعالم!", docText.trim());
Assert.assertFalse(docText.contains(""));
}
boolean value.public void setAddBidiMarks(boolean value)
Specifies whether to add bi-directional marks before each BiDi run when exporting in plain text format.
The default value is false.
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.getParagraphFormat().setBidi(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();
saveOptions.setEncoding(StandardCharsets.UTF_16);
// 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.setAddBidiMarks(addBidiMarks);
doc.save(getArtifactsDir() + "TxtSaveOptions.AddBidiMarks.txt", saveOptions);
String docText = new String(Files.readAllBytes(Paths.get(getArtifactsDir() + "TxtSaveOptions.AddBidiMarks.txt")), StandardCharsets.UTF_16);
if (addBidiMarks) {
Assert.assertEquals("Hello world!\r\nשלום עולם!\r\nمرحبا بالعالم!", docText.trim());
Assert.assertTrue(docText.contains(""));
} else {
Assert.assertEquals("Hello world!\r\nשלום עולם!\r\nمرحبا بالعالم!", docText.trim());
Assert.assertFalse(docText.contains(""));
}
value - The corresponding boolean value.public TxtListIndentation getListIndentation()
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.
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.getListFormat().applyNumberDefault();
builder.writeln("Item 1");
builder.getListFormat().listIndent();
builder.writeln("Item 2");
builder.getListFormat().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.getListIndentation().setCharacter(' ');
// Set the "Count" property to specify the number of times
// to place the padding character for each list indent level.
txtSaveOptions.getListIndentation().setCount(3);
doc.save(getArtifactsDir() + "TxtSaveOptions.TxtListIndentation.txt", txtSaveOptions);
String docText = getArtifactsDir() + "TxtSaveOptions.TxtListIndentation.txt";
TestUtil.fileContainsString("1. Item 1\r\n" +
" a. Item 2\r\n" +
" i. Item 3", docText);
TxtListIndentation object that specifies how many and which character to use for indentation of list levels.public boolean getPreserveTableLayout()
false.
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.setPreserveTableLayout(preserveTableLayout);
doc.save(getArtifactsDir() + "TxtSaveOptions.PreserveTableLayout.txt", txtSaveOptions);
String docText = new Document(getArtifactsDir() + "TxtSaveOptions.PreserveTableLayout.txt").getText().trim();
if (preserveTableLayout)
Assert.assertEquals("Row 1, cell 1 Row 1, cell 2\r" +
"Row 2, cell 1 Row 2, cell 2", docText);
else
Assert.assertEquals("Row 1, cell 1\r" +
"Row 1, cell 2\r" +
"Row 2, cell 1\r" +
"Row 2, cell 2", docText);
boolean value.public void setPreserveTableLayout(boolean value)
false.
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.setPreserveTableLayout(preserveTableLayout);
doc.save(getArtifactsDir() + "TxtSaveOptions.PreserveTableLayout.txt", txtSaveOptions);
String docText = new Document(getArtifactsDir() + "TxtSaveOptions.PreserveTableLayout.txt").getText().trim();
if (preserveTableLayout)
Assert.assertEquals("Row 1, cell 1 Row 1, cell 2\r" +
"Row 2, cell 1 Row 2, cell 2", docText);
else
Assert.assertEquals("Row 1, cell 1\r" +
"Row 1, cell 2\r" +
"Row 2, cell 1\r" +
"Row 2, cell 2", docText);
value - The corresponding boolean value.public int getMaxCharactersPerLine()
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(); { saveOptions.setMaxCharactersPerLine(30); }
doc.save(getArtifactsDir() + "TxtSaveOptions.MaxCharactersPerLine.txt", saveOptions);
public void setMaxCharactersPerLine(int 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(); { saveOptions.setMaxCharactersPerLine(30); }
doc.save(getArtifactsDir() + "TxtSaveOptions.MaxCharactersPerLine.txt", saveOptions);
value - An integer value that specifies the maximum number of characters per one line.public int getOfficeMathExportMode()
TxtOfficeMathExportMode.TEXT.
Examples:
Shows how to export OfficeMath object as Latex in TXT.
Document doc = new Document(getMyDir() + "Office math.docx");
TxtSaveOptions saveOptions = new TxtSaveOptions();
saveOptions.setOfficeMathExportMode(TxtOfficeMathExportMode.LATEX);
doc.save(getArtifactsDir() + "TxtSaveOptions.ExportOfficeMathAsLatexToText.txt", saveOptions);
int value. The returned value is one of TxtOfficeMathExportMode constants.public void setOfficeMathExportMode(int value)
TxtOfficeMathExportMode.TEXT.
Examples:
Shows how to export OfficeMath object as Latex in TXT.
Document doc = new Document(getMyDir() + "Office math.docx");
TxtSaveOptions saveOptions = new TxtSaveOptions();
saveOptions.setOfficeMathExportMode(TxtOfficeMathExportMode.LATEX);
doc.save(getArtifactsDir() + "TxtSaveOptions.ExportOfficeMathAsLatexToText.txt", saveOptions);
value - The corresponding int value. The value must be one of TxtOfficeMathExportMode constants.