Load TXT document with options

GroupDocs.Conversion provides TxtLoadOptions to give you control over how source text document will be processed. The following options could be set: 

  • DetectNumberingWithWhitespaces - allows to specify how numbered list items are recognized when plain text document is converted. 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, white spaces are also used as list number delimiters: list recognition algorithm for Arabic style numbering (1., 1.1.2.) uses both white spaces and dot (".") symbols
  • 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
  • Encoding - specifies encoding to be used to load the document

Control behavior of processing leading spaces

The following code sample shows how to convert txt document and control the way the leading spaces are processed:

Contracts.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);
}

Control behavior of processing trailing spaces

The following code sample shows how to convert txt document and the way the trailing spaces are processed:

Contracts.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);
}

Specify encoding

The following code sample shows how to convert txt document and specify the encoding

Contracts.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);
}

More resources

Examples and Demos

Please find more use-cases and complete C# sources of our backend and frontend examples and try them for free!