Load TXT document with options
Leave feedback
On this page
GroupDocs.Conversion provides TxtLoadOptions to give you control over how the source text document will be processed. The following options could be set:
Option | Description |
---|---|
DetectNumberingWithWhitespaces | Allows specifying how numbered list items are recognized when a plain-text document is converted. If this option is set to false, the list’s recognition algorithm detects list paragraphs, when list numbers end with either dot, right bracket or bullet symbols (such as “•”, “*”, “-” or “o”). If this option is set to true, the white spaces are also used as list number delimiters: the list recognition algorithm for Arabic style numbering (1., 1.1.2.) uses both white spaces and dot (".") symbols. |
Encoding | Specifies the encoding to be used to load the document. |
LeadingSpacesOptions | Specifies how leading spaces will be processed. The available options are: ConvertToIdent, Preserve, Trim |
TrailingSpacesOptions | Specifies how trailing spaces will be processed. The available options are: Preserve, Trim |
The following code snippet shows how to convert a TXT document and control the way the leading spaces are processed:
With v24.10 and later:
Func<LoadContext, LoadOptions> getLoadOptions = loadContext => new TxtLoadOptions
{
LeadingSpacesOptions = TxtLeadingSpacesOptions.ConvertToIndent,
DetectNumberingWithWhitespaces = true
};
using (Converter converter = new Converter("sample.txt", getLoadOptions))
{
PdfConvertOptions options = new PdfConvertOptions();
converter.Convert("converted.pdf", options);
}
Before v24.10:
Func<LoadOptions> getLoadOptions = () => new TxtLoadOptions
{
LeadingSpacesOptions = TxtLeadingSpacesOptions.ConvertToIndent,
DetectNumberingWithWhitespaces = true
};
using (Converter converter = new Converter("sample.txt", getLoadOptions))
{
PdfConvertOptions options = new PdfConvertOptions();
converter.Convert("converted.pdf", options);
}
The following code snippet shows how to convert a TXT document and the way the trailing spaces are processed:
With v24.10 and later:
Func<LoadContext, LoadOptions> getLoadOptions = loadContext => new TxtLoadOptions
{
TrailingSpacesOptions = TxtTrailingSpacesOptions.Trim
};
using (Converter converter = new Converter("sample.txt", getLoadOptions))
{
PdfConvertOptions options = new PdfConvertOptions();
converter.Convert("converted.pdf", options);
}
Before v24.10:
Func<LoadOptions> getLoadOptions = () => new TxtLoadOptions
{
TrailingSpacesOptions = TxtTrailingSpacesOptions.Trim
};
using (Converter converter = new Converter("sample.txt", getLoadOptions))
{
PdfConvertOptions options = new PdfConvertOptions();
converter.Convert("converted.pdf", options);
}
The following code snippet shows how to convert a TXT document and specify the encoding:
With v24.10 and later:
Func<LoadContext, LoadOptions> getLoadOptions = loadContext => new TxtLoadOptions
{
Encoding = Encoding.GetEncoding("shift_jis")
};
using (Converter converter = new Converter("sample.txt", getLoadOptions))
{
PdfConvertOptions options = new PdfConvertOptions();
converter.Convert("converted.pdf", options);
}
Before v24.10:
Func<LoadOptions> getLoadOptions = () => new TxtLoadOptions
{
Encoding = Encoding.GetEncoding("shift_jis")
};
using (Converter converter = new Converter("sample.txt", getLoadOptions))
{
PdfConvertOptions options = new PdfConvertOptions();
converter.Convert("converted.pdf", options);
}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.