public class TxtLoadOptions extends LoadOptions
LoadFormat.TEXT document into a Document object.
To learn more, visit the Specify Load Options documentation article.
Examples:
Shows how to read and display hyperlinks.
final String INPUT_TEXT = "Some links in TXT:\n" +
"https://www.aspose.com/\n" +
"https://docs.aspose.com/words/net/\n";
try (ByteArrayInputStream stream = new ByteArrayInputStream(INPUT_TEXT.getBytes(StandardCharsets.US_ASCII)))
{
// Load document with hyperlinks.
TxtLoadOptions loadOptions = new TxtLoadOptions();
loadOptions.setDetectHyperlinks(true);
Document doc = new Document(stream, loadOptions);
// Print hyperlinks text.
for (Field field : doc.getRange().getFields())
System.out.println(field.getResult());
Assert.assertEquals(doc.getRange().getFields().get(0).getResult().trim(), "https://www.aspose.com/");
Assert.assertEquals(doc.getRange().getFields().get(1).getResult().trim(), "https://docs.aspose.com/words/net/");
}
| Constructor and Description |
|---|
TxtLoadOptions()
Initializes a new instance of this class with default values.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
getAutoNumberingDetection()
Gets a boolean value indicating either automatic numbering detection will be performed while loading a document.
|
boolean |
getDetectHyperlinks()
Specifies either to detect hyperlinks in text.
|
boolean |
getDetectNumberingWithWhitespaces()
Allows to specify how numbered list items are recognized when document is imported from plain text format.
|
int |
getDocumentDirection()
Gets a document direction.
|
int |
getLeadingSpacesOptions()
Gets preferred option of a leading space handling.
|
int |
getTrailingSpacesOptions()
Gets preferred option of a trailing space handling.
|
void |
setAutoNumberingDetection(boolean value)
Sets a boolean value indicating either automatic numbering detection will be performed while loading a document.
|
void |
setDetectHyperlinks(boolean value)
Specifies either to detect hyperlinks in text.
|
void |
setDetectNumberingWithWhitespaces(boolean value)
Allows to specify how numbered list items are recognized when document is imported from plain text format.
|
void |
setDocumentDirection(int value)
Sets a document direction.
|
void |
setLeadingSpacesOptions(int value)
Sets preferred option of a leading space handling.
|
void |
setTrailingSpacesOptions(int value)
Sets preferred option of a trailing space handling.
|
equals, getBaseUri, getConvertMetafilesToPng, getConvertShapeToOfficeMath, getEncoding, getFontSettings, getIgnoreOleData, getLanguagePreferences, getLoadFormat, getMswVersion, getPassword, getPreserveIncludePictureField, getProgressCallback, getRecoveryMode, getResourceLoadingCallback, getTempFolder, getUpdateDirtyFields, getUseSystemLcid, getWarningCallback, setBaseUri, setConvertMetafilesToPng, setConvertShapeToOfficeMath, setEncoding, setFontSettings, setIgnoreOleData, setLoadFormat, setMswVersion, setPassword, setPreserveIncludePictureField, setProgressCallback, setRecoveryMode, setResourceLoadingCallback, setTempFolder, setUpdateDirtyFields, setUseSystemLcid, setWarningCallbackpublic TxtLoadOptions()
Examples:
Shows how to read and display hyperlinks.
final String INPUT_TEXT = "Some links in TXT:\n" +
"https://www.aspose.com/\n" +
"https://docs.aspose.com/words/net/\n";
try (ByteArrayInputStream stream = new ByteArrayInputStream(INPUT_TEXT.getBytes(StandardCharsets.US_ASCII)))
{
// Load document with hyperlinks.
TxtLoadOptions loadOptions = new TxtLoadOptions();
loadOptions.setDetectHyperlinks(true);
Document doc = new Document(stream, loadOptions);
// Print hyperlinks text.
for (Field field : doc.getRange().getFields())
System.out.println(field.getResult());
Assert.assertEquals(doc.getRange().getFields().get(0).getResult().trim(), "https://www.aspose.com/");
Assert.assertEquals(doc.getRange().getFields().get(1).getResult().trim(), "https://docs.aspose.com/words/net/");
}
public boolean getAutoNumberingDetection()
true.
Examples:
Shows how to disable automatic numbering detection.
TxtLoadOptions options = new TxtLoadOptions(); { options.setAutoNumberingDetection(false); }
Document doc = new Document(getMyDir() + "Number detection.txt", options);
public void setAutoNumberingDetection(boolean value)
true.
Examples:
Shows how to disable automatic numbering detection.
TxtLoadOptions options = new TxtLoadOptions(); { options.setAutoNumberingDetection(false); }
Document doc = new Document(getMyDir() + "Number detection.txt", options);
value - A boolean value indicating either automatic numbering detection will be performed while loading a document.public boolean getDetectNumberingWithWhitespaces()
true.
Remarks:
If this option is set to false, lists recognition algorithm detects list paragraphs, when list numbers ends with either dot, right bracket or bullet symbols (such as "•", "*", "-" or "o").
If this option is set to true, whitespaces are also used as list number delimiters: list recognition algorithm for Arabic style numbering (1., 1.1.2.) uses both whitespaces and dot (".") symbols.
Examples:
Shows how to detect lists when loading plaintext documents.
// Create a plaintext document in a string with four separate parts that we may interpret as lists,
// with different delimiters. Upon loading the plaintext document into a "Document" object,
// Aspose.Words will always detect the first three lists and will add a "List" object
// for each to the document's "Lists" property.
final String TEXT_DOC = "Full stop delimiters:\n" +
"1. First list item 1\n" +
"2. First list item 2\n" +
"3. First list item 3\n\n" +
"Right bracket delimiters:\n" +
"1) Second list item 1\n" +
"2) Second list item 2\n" +
"3) Second list item 3\n\n" +
"Bullet delimiters:\n" +
"• Third list item 1\n" +
"• Third list item 2\n" +
"• Third list item 3\n\n" +
"Whitespace delimiters:\n" +
"1 Fourth list item 1\n" +
"2 Fourth list item 2\n" +
"3 Fourth list item 3";
// Create a "TxtLoadOptions" object, which we can pass to a document's constructor
// to modify how we load a plaintext document.
TxtLoadOptions loadOptions = new TxtLoadOptions();
// Set the "DetectNumberingWithWhitespaces" property to "true" to detect numbered items
// with whitespace delimiters, such as the fourth list in our document, as lists.
// This may also falsely detect paragraphs that begin with numbers as lists.
// Set the "DetectNumberingWithWhitespaces" property to "false"
// to not create lists from numbered items with whitespace delimiters.
loadOptions.setDetectNumberingWithWhitespaces(detectNumberingWithWhitespaces);
Document doc = new Document(new ByteArrayInputStream(TEXT_DOC.getBytes()), loadOptions);
List<Paragraph> paragraphList = Arrays.stream(doc.getFirstSection().getBody().getParagraphs().toArray())
.filter(Paragraph.class::isInstance)
.map(Paragraph.class::cast)
.collect(Collectors.toList());
if (detectNumberingWithWhitespaces) {
Assert.assertEquals(4, doc.getLists().getCount());
Assert.assertTrue(IterableUtils.matchesAny(paragraphList, s -> s.getText().contains("Fourth list") && s.isListItem()));
} else {
Assert.assertEquals(3, doc.getLists().getCount());
Assert.assertFalse(IterableUtils.matchesAny(paragraphList, s -> s.getText().contains("Fourth list") && s.isListItem()));
}
boolean value.public void setDetectNumberingWithWhitespaces(boolean value)
true.
Remarks:
If this option is set to false, lists recognition algorithm detects list paragraphs, when list numbers ends with either dot, right bracket or bullet symbols (such as "•", "*", "-" or "o").
If this option is set to true, whitespaces are also used as list number delimiters: list recognition algorithm for Arabic style numbering (1., 1.1.2.) uses both whitespaces and dot (".") symbols.
Examples:
Shows how to detect lists when loading plaintext documents.
// Create a plaintext document in a string with four separate parts that we may interpret as lists,
// with different delimiters. Upon loading the plaintext document into a "Document" object,
// Aspose.Words will always detect the first three lists and will add a "List" object
// for each to the document's "Lists" property.
final String TEXT_DOC = "Full stop delimiters:\n" +
"1. First list item 1\n" +
"2. First list item 2\n" +
"3. First list item 3\n\n" +
"Right bracket delimiters:\n" +
"1) Second list item 1\n" +
"2) Second list item 2\n" +
"3) Second list item 3\n\n" +
"Bullet delimiters:\n" +
"• Third list item 1\n" +
"• Third list item 2\n" +
"• Third list item 3\n\n" +
"Whitespace delimiters:\n" +
"1 Fourth list item 1\n" +
"2 Fourth list item 2\n" +
"3 Fourth list item 3";
// Create a "TxtLoadOptions" object, which we can pass to a document's constructor
// to modify how we load a plaintext document.
TxtLoadOptions loadOptions = new TxtLoadOptions();
// Set the "DetectNumberingWithWhitespaces" property to "true" to detect numbered items
// with whitespace delimiters, such as the fourth list in our document, as lists.
// This may also falsely detect paragraphs that begin with numbers as lists.
// Set the "DetectNumberingWithWhitespaces" property to "false"
// to not create lists from numbered items with whitespace delimiters.
loadOptions.setDetectNumberingWithWhitespaces(detectNumberingWithWhitespaces);
Document doc = new Document(new ByteArrayInputStream(TEXT_DOC.getBytes()), loadOptions);
List<Paragraph> paragraphList = Arrays.stream(doc.getFirstSection().getBody().getParagraphs().toArray())
.filter(Paragraph.class::isInstance)
.map(Paragraph.class::cast)
.collect(Collectors.toList());
if (detectNumberingWithWhitespaces) {
Assert.assertEquals(4, doc.getLists().getCount());
Assert.assertTrue(IterableUtils.matchesAny(paragraphList, s -> s.getText().contains("Fourth list") && s.isListItem()));
} else {
Assert.assertEquals(3, doc.getLists().getCount());
Assert.assertFalse(IterableUtils.matchesAny(paragraphList, s -> s.getText().contains("Fourth list") && s.isListItem()));
}
value - The corresponding boolean value.public int getTrailingSpacesOptions()
TxtTrailingSpacesOptions.TRIM.
Examples:
Shows how to trim whitespace when loading plaintext documents.
String textDoc = " Line 1 \n" +
" Line 2 \n" +
" Line 3 ";
// Create a "TxtLoadOptions" object, which we can pass to a document's constructor
// to modify how we load a plaintext document.
TxtLoadOptions loadOptions = new TxtLoadOptions();
// Set the "LeadingSpacesOptions" property to "TxtLeadingSpacesOptions.Preserve"
// to preserve all whitespace characters at the start of every line.
// Set the "LeadingSpacesOptions" property to "TxtLeadingSpacesOptions.ConvertToIndent"
// to remove all whitespace characters from the start of every line,
// and then apply a left first line indent to the paragraph to simulate the effect of the whitespaces.
// Set the "LeadingSpacesOptions" property to "TxtLeadingSpacesOptions.Trim"
// to remove all whitespace characters from every line's start.
loadOptions.setLeadingSpacesOptions(txtLeadingSpacesOptions);
// Set the "TrailingSpacesOptions" property to "TxtTrailingSpacesOptions.Preserve"
// to preserve all whitespace characters at the end of every line.
// Set the "TrailingSpacesOptions" property to "TxtTrailingSpacesOptions.Trim" to
// remove all whitespace characters from the end of every line.
loadOptions.setTrailingSpacesOptions(txtTrailingSpacesOptions);
Document doc = new Document(new ByteArrayInputStream(textDoc.getBytes()), loadOptions);
ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
switch (txtLeadingSpacesOptions) {
case TxtLeadingSpacesOptions.CONVERT_TO_INDENT:
Assert.assertEquals(37.8d, paragraphs.get(0).getParagraphFormat().getFirstLineIndent());
Assert.assertEquals(25.2d, paragraphs.get(1).getParagraphFormat().getFirstLineIndent());
Assert.assertEquals(6.3d, paragraphs.get(2).getParagraphFormat().getFirstLineIndent());
Assert.assertTrue(paragraphs.get(0).getText().startsWith("Line 1"));
Assert.assertTrue(paragraphs.get(1).getText().startsWith("Line 2"));
Assert.assertTrue(paragraphs.get(2).getText().startsWith("Line 3"));
break;
case TxtLeadingSpacesOptions.PRESERVE:
Assert.assertTrue(IterableUtils.matchesAll(paragraphs, s -> s.getParagraphFormat().getFirstLineIndent() == 0.0d));
Assert.assertTrue(paragraphs.get(0).getText().startsWith(" Line 1"));
Assert.assertTrue(paragraphs.get(1).getText().startsWith(" Line 2"));
Assert.assertTrue(paragraphs.get(2).getText().startsWith(" Line 3"));
break;
case TxtLeadingSpacesOptions.TRIM:
Assert.assertTrue(IterableUtils.matchesAll(paragraphs, s -> s.getParagraphFormat().getFirstLineIndent() == 0.0d));
Assert.assertTrue(paragraphs.get(0).getText().startsWith("Line 1"));
Assert.assertTrue(paragraphs.get(1).getText().startsWith("Line 2"));
Assert.assertTrue(paragraphs.get(2).getText().startsWith("Line 3"));
break;
}
switch (txtTrailingSpacesOptions) {
case TxtTrailingSpacesOptions.PRESERVE:
Assert.assertTrue(paragraphs.get(0).getText().endsWith("Line 1 \r"));
Assert.assertTrue(paragraphs.get(1).getText().endsWith("Line 2 \r"));
Assert.assertTrue(paragraphs.get(2).getText().endsWith("Line 3 \f"));
break;
case TxtTrailingSpacesOptions.TRIM:
Assert.assertTrue(paragraphs.get(0).getText().endsWith("Line 1\r"));
Assert.assertTrue(paragraphs.get(1).getText().endsWith("Line 2\r"));
Assert.assertTrue(paragraphs.get(2).getText().endsWith("Line 3\f"));
break;
}
TxtTrailingSpacesOptions constants.public void setTrailingSpacesOptions(int value)
TxtTrailingSpacesOptions.TRIM.
Examples:
Shows how to trim whitespace when loading plaintext documents.
String textDoc = " Line 1 \n" +
" Line 2 \n" +
" Line 3 ";
// Create a "TxtLoadOptions" object, which we can pass to a document's constructor
// to modify how we load a plaintext document.
TxtLoadOptions loadOptions = new TxtLoadOptions();
// Set the "LeadingSpacesOptions" property to "TxtLeadingSpacesOptions.Preserve"
// to preserve all whitespace characters at the start of every line.
// Set the "LeadingSpacesOptions" property to "TxtLeadingSpacesOptions.ConvertToIndent"
// to remove all whitespace characters from the start of every line,
// and then apply a left first line indent to the paragraph to simulate the effect of the whitespaces.
// Set the "LeadingSpacesOptions" property to "TxtLeadingSpacesOptions.Trim"
// to remove all whitespace characters from every line's start.
loadOptions.setLeadingSpacesOptions(txtLeadingSpacesOptions);
// Set the "TrailingSpacesOptions" property to "TxtTrailingSpacesOptions.Preserve"
// to preserve all whitespace characters at the end of every line.
// Set the "TrailingSpacesOptions" property to "TxtTrailingSpacesOptions.Trim" to
// remove all whitespace characters from the end of every line.
loadOptions.setTrailingSpacesOptions(txtTrailingSpacesOptions);
Document doc = new Document(new ByteArrayInputStream(textDoc.getBytes()), loadOptions);
ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
switch (txtLeadingSpacesOptions) {
case TxtLeadingSpacesOptions.CONVERT_TO_INDENT:
Assert.assertEquals(37.8d, paragraphs.get(0).getParagraphFormat().getFirstLineIndent());
Assert.assertEquals(25.2d, paragraphs.get(1).getParagraphFormat().getFirstLineIndent());
Assert.assertEquals(6.3d, paragraphs.get(2).getParagraphFormat().getFirstLineIndent());
Assert.assertTrue(paragraphs.get(0).getText().startsWith("Line 1"));
Assert.assertTrue(paragraphs.get(1).getText().startsWith("Line 2"));
Assert.assertTrue(paragraphs.get(2).getText().startsWith("Line 3"));
break;
case TxtLeadingSpacesOptions.PRESERVE:
Assert.assertTrue(IterableUtils.matchesAll(paragraphs, s -> s.getParagraphFormat().getFirstLineIndent() == 0.0d));
Assert.assertTrue(paragraphs.get(0).getText().startsWith(" Line 1"));
Assert.assertTrue(paragraphs.get(1).getText().startsWith(" Line 2"));
Assert.assertTrue(paragraphs.get(2).getText().startsWith(" Line 3"));
break;
case TxtLeadingSpacesOptions.TRIM:
Assert.assertTrue(IterableUtils.matchesAll(paragraphs, s -> s.getParagraphFormat().getFirstLineIndent() == 0.0d));
Assert.assertTrue(paragraphs.get(0).getText().startsWith("Line 1"));
Assert.assertTrue(paragraphs.get(1).getText().startsWith("Line 2"));
Assert.assertTrue(paragraphs.get(2).getText().startsWith("Line 3"));
break;
}
switch (txtTrailingSpacesOptions) {
case TxtTrailingSpacesOptions.PRESERVE:
Assert.assertTrue(paragraphs.get(0).getText().endsWith("Line 1 \r"));
Assert.assertTrue(paragraphs.get(1).getText().endsWith("Line 2 \r"));
Assert.assertTrue(paragraphs.get(2).getText().endsWith("Line 3 \f"));
break;
case TxtTrailingSpacesOptions.TRIM:
Assert.assertTrue(paragraphs.get(0).getText().endsWith("Line 1\r"));
Assert.assertTrue(paragraphs.get(1).getText().endsWith("Line 2\r"));
Assert.assertTrue(paragraphs.get(2).getText().endsWith("Line 3\f"));
break;
}
value - Preferred option of a trailing space handling. The value must be one of TxtTrailingSpacesOptions constants.public int getLeadingSpacesOptions()
TxtLeadingSpacesOptions.CONVERT_TO_INDENT.
Examples:
Shows how to trim whitespace when loading plaintext documents.
String textDoc = " Line 1 \n" +
" Line 2 \n" +
" Line 3 ";
// Create a "TxtLoadOptions" object, which we can pass to a document's constructor
// to modify how we load a plaintext document.
TxtLoadOptions loadOptions = new TxtLoadOptions();
// Set the "LeadingSpacesOptions" property to "TxtLeadingSpacesOptions.Preserve"
// to preserve all whitespace characters at the start of every line.
// Set the "LeadingSpacesOptions" property to "TxtLeadingSpacesOptions.ConvertToIndent"
// to remove all whitespace characters from the start of every line,
// and then apply a left first line indent to the paragraph to simulate the effect of the whitespaces.
// Set the "LeadingSpacesOptions" property to "TxtLeadingSpacesOptions.Trim"
// to remove all whitespace characters from every line's start.
loadOptions.setLeadingSpacesOptions(txtLeadingSpacesOptions);
// Set the "TrailingSpacesOptions" property to "TxtTrailingSpacesOptions.Preserve"
// to preserve all whitespace characters at the end of every line.
// Set the "TrailingSpacesOptions" property to "TxtTrailingSpacesOptions.Trim" to
// remove all whitespace characters from the end of every line.
loadOptions.setTrailingSpacesOptions(txtTrailingSpacesOptions);
Document doc = new Document(new ByteArrayInputStream(textDoc.getBytes()), loadOptions);
ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
switch (txtLeadingSpacesOptions) {
case TxtLeadingSpacesOptions.CONVERT_TO_INDENT:
Assert.assertEquals(37.8d, paragraphs.get(0).getParagraphFormat().getFirstLineIndent());
Assert.assertEquals(25.2d, paragraphs.get(1).getParagraphFormat().getFirstLineIndent());
Assert.assertEquals(6.3d, paragraphs.get(2).getParagraphFormat().getFirstLineIndent());
Assert.assertTrue(paragraphs.get(0).getText().startsWith("Line 1"));
Assert.assertTrue(paragraphs.get(1).getText().startsWith("Line 2"));
Assert.assertTrue(paragraphs.get(2).getText().startsWith("Line 3"));
break;
case TxtLeadingSpacesOptions.PRESERVE:
Assert.assertTrue(IterableUtils.matchesAll(paragraphs, s -> s.getParagraphFormat().getFirstLineIndent() == 0.0d));
Assert.assertTrue(paragraphs.get(0).getText().startsWith(" Line 1"));
Assert.assertTrue(paragraphs.get(1).getText().startsWith(" Line 2"));
Assert.assertTrue(paragraphs.get(2).getText().startsWith(" Line 3"));
break;
case TxtLeadingSpacesOptions.TRIM:
Assert.assertTrue(IterableUtils.matchesAll(paragraphs, s -> s.getParagraphFormat().getFirstLineIndent() == 0.0d));
Assert.assertTrue(paragraphs.get(0).getText().startsWith("Line 1"));
Assert.assertTrue(paragraphs.get(1).getText().startsWith("Line 2"));
Assert.assertTrue(paragraphs.get(2).getText().startsWith("Line 3"));
break;
}
switch (txtTrailingSpacesOptions) {
case TxtTrailingSpacesOptions.PRESERVE:
Assert.assertTrue(paragraphs.get(0).getText().endsWith("Line 1 \r"));
Assert.assertTrue(paragraphs.get(1).getText().endsWith("Line 2 \r"));
Assert.assertTrue(paragraphs.get(2).getText().endsWith("Line 3 \f"));
break;
case TxtTrailingSpacesOptions.TRIM:
Assert.assertTrue(paragraphs.get(0).getText().endsWith("Line 1\r"));
Assert.assertTrue(paragraphs.get(1).getText().endsWith("Line 2\r"));
Assert.assertTrue(paragraphs.get(2).getText().endsWith("Line 3\f"));
break;
}
TxtLeadingSpacesOptions constants.public void setLeadingSpacesOptions(int value)
TxtLeadingSpacesOptions.CONVERT_TO_INDENT.
Examples:
Shows how to trim whitespace when loading plaintext documents.
String textDoc = " Line 1 \n" +
" Line 2 \n" +
" Line 3 ";
// Create a "TxtLoadOptions" object, which we can pass to a document's constructor
// to modify how we load a plaintext document.
TxtLoadOptions loadOptions = new TxtLoadOptions();
// Set the "LeadingSpacesOptions" property to "TxtLeadingSpacesOptions.Preserve"
// to preserve all whitespace characters at the start of every line.
// Set the "LeadingSpacesOptions" property to "TxtLeadingSpacesOptions.ConvertToIndent"
// to remove all whitespace characters from the start of every line,
// and then apply a left first line indent to the paragraph to simulate the effect of the whitespaces.
// Set the "LeadingSpacesOptions" property to "TxtLeadingSpacesOptions.Trim"
// to remove all whitespace characters from every line's start.
loadOptions.setLeadingSpacesOptions(txtLeadingSpacesOptions);
// Set the "TrailingSpacesOptions" property to "TxtTrailingSpacesOptions.Preserve"
// to preserve all whitespace characters at the end of every line.
// Set the "TrailingSpacesOptions" property to "TxtTrailingSpacesOptions.Trim" to
// remove all whitespace characters from the end of every line.
loadOptions.setTrailingSpacesOptions(txtTrailingSpacesOptions);
Document doc = new Document(new ByteArrayInputStream(textDoc.getBytes()), loadOptions);
ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
switch (txtLeadingSpacesOptions) {
case TxtLeadingSpacesOptions.CONVERT_TO_INDENT:
Assert.assertEquals(37.8d, paragraphs.get(0).getParagraphFormat().getFirstLineIndent());
Assert.assertEquals(25.2d, paragraphs.get(1).getParagraphFormat().getFirstLineIndent());
Assert.assertEquals(6.3d, paragraphs.get(2).getParagraphFormat().getFirstLineIndent());
Assert.assertTrue(paragraphs.get(0).getText().startsWith("Line 1"));
Assert.assertTrue(paragraphs.get(1).getText().startsWith("Line 2"));
Assert.assertTrue(paragraphs.get(2).getText().startsWith("Line 3"));
break;
case TxtLeadingSpacesOptions.PRESERVE:
Assert.assertTrue(IterableUtils.matchesAll(paragraphs, s -> s.getParagraphFormat().getFirstLineIndent() == 0.0d));
Assert.assertTrue(paragraphs.get(0).getText().startsWith(" Line 1"));
Assert.assertTrue(paragraphs.get(1).getText().startsWith(" Line 2"));
Assert.assertTrue(paragraphs.get(2).getText().startsWith(" Line 3"));
break;
case TxtLeadingSpacesOptions.TRIM:
Assert.assertTrue(IterableUtils.matchesAll(paragraphs, s -> s.getParagraphFormat().getFirstLineIndent() == 0.0d));
Assert.assertTrue(paragraphs.get(0).getText().startsWith("Line 1"));
Assert.assertTrue(paragraphs.get(1).getText().startsWith("Line 2"));
Assert.assertTrue(paragraphs.get(2).getText().startsWith("Line 3"));
break;
}
switch (txtTrailingSpacesOptions) {
case TxtTrailingSpacesOptions.PRESERVE:
Assert.assertTrue(paragraphs.get(0).getText().endsWith("Line 1 \r"));
Assert.assertTrue(paragraphs.get(1).getText().endsWith("Line 2 \r"));
Assert.assertTrue(paragraphs.get(2).getText().endsWith("Line 3 \f"));
break;
case TxtTrailingSpacesOptions.TRIM:
Assert.assertTrue(paragraphs.get(0).getText().endsWith("Line 1\r"));
Assert.assertTrue(paragraphs.get(1).getText().endsWith("Line 2\r"));
Assert.assertTrue(paragraphs.get(2).getText().endsWith("Line 3\f"));
break;
}
value - Preferred option of a leading space handling. The value must be one of TxtLeadingSpacesOptions constants.public int getDocumentDirection()
DocumentDirection.LEFT_TO_RIGHT.
Examples:
Shows how to detect plaintext document text direction.
// Create a "TxtLoadOptions" object, which we can pass to a document's constructor
// to modify how we load a plaintext document.
TxtLoadOptions loadOptions = new TxtLoadOptions();
// Set the "DocumentDirection" property to "DocumentDirection.Auto" automatically detects
// the direction of every paragraph of text that Aspose.Words loads from plaintext.
// Each paragraph's "Bidi" property will store its direction.
loadOptions.setDocumentDirection(DocumentDirection.AUTO);
// Detect Hebrew text as right-to-left.
Document doc = new Document(getMyDir() + "Hebrew text.txt", loadOptions);
Assert.assertTrue(doc.getFirstSection().getBody().getFirstParagraph().getParagraphFormat().getBidi());
// Detect English text as right-to-left.
doc = new Document(getMyDir() + "English text.txt", loadOptions);
Assert.assertFalse(doc.getFirstSection().getBody().getFirstParagraph().getParagraphFormat().getBidi());
DocumentDirection constants.public void setDocumentDirection(int value)
DocumentDirection.LEFT_TO_RIGHT.
Examples:
Shows how to detect plaintext document text direction.
// Create a "TxtLoadOptions" object, which we can pass to a document's constructor
// to modify how we load a plaintext document.
TxtLoadOptions loadOptions = new TxtLoadOptions();
// Set the "DocumentDirection" property to "DocumentDirection.Auto" automatically detects
// the direction of every paragraph of text that Aspose.Words loads from plaintext.
// Each paragraph's "Bidi" property will store its direction.
loadOptions.setDocumentDirection(DocumentDirection.AUTO);
// Detect Hebrew text as right-to-left.
Document doc = new Document(getMyDir() + "Hebrew text.txt", loadOptions);
Assert.assertTrue(doc.getFirstSection().getBody().getFirstParagraph().getParagraphFormat().getBidi());
// Detect English text as right-to-left.
doc = new Document(getMyDir() + "English text.txt", loadOptions);
Assert.assertFalse(doc.getFirstSection().getBody().getFirstParagraph().getParagraphFormat().getBidi());
value - A document direction. The value must be one of DocumentDirection constants.public boolean getDetectHyperlinks()
false.
Examples:
Shows how to read and display hyperlinks.
final String INPUT_TEXT = "Some links in TXT:\n" +
"https://www.aspose.com/\n" +
"https://docs.aspose.com/words/net/\n";
try (ByteArrayInputStream stream = new ByteArrayInputStream(INPUT_TEXT.getBytes(StandardCharsets.US_ASCII)))
{
// Load document with hyperlinks.
TxtLoadOptions loadOptions = new TxtLoadOptions();
loadOptions.setDetectHyperlinks(true);
Document doc = new Document(stream, loadOptions);
// Print hyperlinks text.
for (Field field : doc.getRange().getFields())
System.out.println(field.getResult());
Assert.assertEquals(doc.getRange().getFields().get(0).getResult().trim(), "https://www.aspose.com/");
Assert.assertEquals(doc.getRange().getFields().get(1).getResult().trim(), "https://docs.aspose.com/words/net/");
}
boolean value.public void setDetectHyperlinks(boolean value)
false.
Examples:
Shows how to read and display hyperlinks.
final String INPUT_TEXT = "Some links in TXT:\n" +
"https://www.aspose.com/\n" +
"https://docs.aspose.com/words/net/\n";
try (ByteArrayInputStream stream = new ByteArrayInputStream(INPUT_TEXT.getBytes(StandardCharsets.US_ASCII)))
{
// Load document with hyperlinks.
TxtLoadOptions loadOptions = new TxtLoadOptions();
loadOptions.setDetectHyperlinks(true);
Document doc = new Document(stream, loadOptions);
// Print hyperlinks text.
for (Field field : doc.getRange().getFields())
System.out.println(field.getResult());
Assert.assertEquals(doc.getRange().getFields().get(0).getResult().trim(), "https://www.aspose.com/");
Assert.assertEquals(doc.getRange().getFields().get(1).getResult().trim(), "https://docs.aspose.com/words/net/");
}
value - The corresponding boolean value.