Пример #1
0
        public static void Run()
        {
            try
            {
                // Create necessary API instances
                var apiInstance = new ConvertApi(Constants.GetConfig());

                // Prepare convert settings
                var loadOptions = new TxtLoadOptions
                {
                    Encoding = "shift_jis"
                };

                var settings = new ConvertSettings
                {
                    StorageName = Constants.MyStorage,
                    FilePath    = "Text/sample.txt",
                    Format      = "pdf",
                    LoadOptions = loadOptions,
                    OutputPath  = "converted"
                };

                // Convert to specified format
                var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings));
                Console.WriteLine("Document converted successfully: " + response[0].Url);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
        }
        public static void Main()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir  = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            string filePath = dataDir + "Book11.csv";

            // Instantiate Text File's LoadOptions
            TxtLoadOptions txtLoadOptions = new TxtLoadOptions();

            // Specify the separator
            txtLoadOptions.Separator = Convert.ToChar(",");

            // Specify the encoding type
            txtLoadOptions.Encoding = System.Text.Encoding.UTF8;

            // Create a Workbook object and opening the file from its path
            Workbook wb = new Workbook(filePath, txtLoadOptions);

            // Save file
            wb.Save(dataDir + "output.txt");
            // ExEnd:1

            Console.WriteLine("OpeningTextFilewithCustomSeparator executed successfully.\r\n");
        }
Пример #3
0
        public static void Run()
        {
            // ExStart:ConvertTextToColumns
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Create a workbook.
            Workbook wb = new Workbook();

            //Access first worksheet.
            Worksheet ws = wb.Worksheets[0];

            //Add people name in column A. Fast name and Last name are separated by space.
            ws.Cells["A1"].PutValue("John Teal");
            ws.Cells["A2"].PutValue("Peter Graham");
            ws.Cells["A3"].PutValue("Brady Cortez");
            ws.Cells["A4"].PutValue("Mack Nick");
            ws.Cells["A5"].PutValue("Hsu Lee");

            //Create text load options with space as separator.
            TxtLoadOptions opts = new TxtLoadOptions();

            opts.Separator = ' ';

            //Split the column A into two columns using TextToColumns() method.
            //Now column A will have first name and column B will have second name.
            ws.Cells.TextToColumns(0, 0, 5, opts);

            //Save the workbook in xlsx format.
            wb.Save(dataDir + "outputTextToColumns.xlsx");

            // ExEnd:ConvertTextToColumns
        }
Пример #4
0
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            //Output directory
            string outputDir = RunExamples.Get_OutputDirectory();

            TxtLoadOptions opts = new TxtLoadOptions();

            opts.Separator  = ',';
            opts.HasFormula = true;

            // Load your CSV file with formulas in a Workbook object
            Workbook workbook = new Workbook(sourceDir + "sampleImportCSVWithFormulas.csv", opts);

            // You can also import your CSV file like this
            // The code below is importing CSV file starting from cell D4
            Worksheet worksheet = workbook.Worksheets[0];

            worksheet.Cells.ImportCSV(sourceDir + "sampleImportCSVWithFormulas.csv", opts, 3, 3);

            // Save your workbook in Xlsx format
            workbook.Save(outputDir + "outputImportCSVWithFormulas.xlsx");

            Console.WriteLine("ImportCSVWithFormulas executed successfully.");
        }
        public void DetectDocumentDirection()
        {
            //ExStart
            //ExFor:TxtLoadOptions.DocumentDirection
            //ExFor:ParagraphFormat.Bidi
            //ExSummary: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.DocumentDirection = DocumentDirection.Auto;

            // Detect Hebrew text as right-to-left.
            Document doc = new Document(MyDir + "Hebrew text.txt", loadOptions);

            Assert.True(doc.FirstSection.Body.FirstParagraph.ParagraphFormat.Bidi);

            // Detect English text as right-to-left.
            doc = new Document(MyDir + "English text.txt", loadOptions);

            Assert.False(doc.FirstSection.Body.FirstParagraph.ParagraphFormat.Bidi);
            //ExEnd
        }
        public void DetectNumberingWithWhitespaces(bool detectNumberingWithWhitespaces)
        {
            //ExStart
            //ExFor:TxtLoadOptions.DetectNumberingWithWhitespaces
            //ExSummary: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.
            const string textDoc = "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.DetectNumberingWithWhitespaces = detectNumberingWithWhitespaces;

            Document doc = new Document(new MemoryStream(Encoding.UTF8.GetBytes(textDoc)), loadOptions);

            if (detectNumberingWithWhitespaces)
            {
                Assert.AreEqual(4, doc.Lists.Count);
                Assert.True(doc.FirstSection.Body.Paragraphs.Any(p => p.GetText().Contains("Fourth list") && ((Paragraph)p).IsListItem));
            }
            else
            {
                Assert.AreEqual(3, doc.Lists.Count);
                Assert.False(doc.FirstSection.Body.Paragraphs.Any(p => p.GetText().Contains("Fourth list") && ((Paragraph)p).IsListItem));
            }
            //ExEnd
        }
        public static void HandleSpacesOptions(string dataDir)
        {
            //ExStart:HandleSpacesOptions
            TxtLoadOptions loadOptions = new TxtLoadOptions();

            loadOptions.LeadingSpacesOptions  = TxtLeadingSpacesOptions.Trim;
            loadOptions.TrailingSpacesOptions = TxtTrailingSpacesOptions.Trim;
            Document doc = new Document(dataDir + "LoadTxt.txt", loadOptions);

            dataDir = dataDir + "HandleSpacesOptions_out.docx";
            doc.Save(dataDir);
            //ExEnd:HandleSpacesOptions
            Console.WriteLine("\nTrim leading and trailing spaces while importing text document.\nFile saved at " + dataDir);
        }
        public static void DetectNumberingWithWhitespaces(string dataDir)
        {
            //ExStart:DetectNumberingWithWhitespaces
            TxtLoadOptions loadOptions = new TxtLoadOptions();

            loadOptions.DetectNumberingWithWhitespaces = false;

            Document doc = new Document(dataDir + "LoadTxt.txt", loadOptions);

            dataDir = dataDir + "DetectNumberingWithWhitespaces_out.docx";
            doc.Save(dataDir);
            //ExEnd:DetectNumberingWithWhitespaces
            Console.WriteLine("\nDetect number with whitespaces successfully.\nFile saved at " + dataDir);
        }
        public void DetectDocumentDirection(string documentPath, bool isBidi)
        {
            //ExStart
            //ExFor:TxtLoadOptions.DocumentDirection
            //ExSummary:Shows how to detect document direction automatically.
            TxtLoadOptions loadOptions = new TxtLoadOptions();

            loadOptions.DocumentDirection = DocumentDirection.Auto;

            // Text like Hebrew/Arabic will be automatically detected as RTL
            Document  doc       = new Document(MyDir + documentPath, loadOptions);
            Paragraph paragraph = doc.FirstSection.Body.FirstParagraph;

            Assert.AreEqual(isBidi, paragraph.ParagraphFormat.Bidi);
            //ExEnd
        }
        public void DocumentTextDirection()
        {
            //ExStart:DocumentTextDirection
            TxtLoadOptions loadOptions = new TxtLoadOptions {
                DocumentDirection = DocumentDirection.Auto
            };

            Document doc = new Document(MyDir + "Hebrew text.txt", loadOptions);

            Paragraph paragraph = doc.FirstSection.Body.FirstParagraph;

            Console.WriteLine(paragraph.ParagraphFormat.Bidi);

            doc.Save(ArtifactsDir + "WorkingWithTxtLoadOptions.DocumentTextDirection.docx");
            //ExEnd:DocumentTextDirection
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            string filePath = dataDir + "MultiEncoded.csv";

            //Set Multi Encoded Property to True
            TxtLoadOptions options = new TxtLoadOptions();
            options.IsMultiEncoded = true;

            //Load the CSV file into Workbook
            Workbook workbook = new Workbook(filePath, options);

            //Save it in XLSX format
            workbook.Save( filePath + ".out.xlsx", SaveFormat.Xlsx);
        }
        public void DetectNumberingWithWhitespaces(bool detectNumberingWithWhitespaces)
        {
            //ExStart
            //ExFor:TxtLoadOptions.DetectNumberingWithWhitespaces
            //ExSummary:Shows how lists are detected when plaintext documents are loaded.
            // Create a plaintext document in the form of a string with parts that may be interpreted as lists
            // Upon loading, the first three lists will always be detected by Aspose.Words, and List objects will be created for them after loading
            string textDoc = "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";

            // The fourth list, with whitespace inbetween the list number and list item contents,
            // will only be detected as a list if "DetectNumberingWithWhitespaces" in a LoadOptions object is set to true,
            // to avoid paragraphs that start with numbers being mistakenly detected as lists
            TxtLoadOptions loadOptions = new TxtLoadOptions();

            loadOptions.DetectNumberingWithWhitespaces = detectNumberingWithWhitespaces;

            // Load the document while applying LoadOptions as a parameter and verify the result
            Document doc = new Document(new MemoryStream(Encoding.UTF8.GetBytes(textDoc)), loadOptions);

            if (detectNumberingWithWhitespaces)
            {
                Assert.AreEqual(4, doc.Lists.Count);
                Assert.True(doc.FirstSection.Body.Paragraphs.Any(p => p.GetText().Contains("Fourth list") && ((Paragraph)p).IsListItem));
            }
            else
            {
                Assert.AreEqual(3, doc.Lists.Count);
                Assert.False(doc.FirstSection.Body.Paragraphs.Any(p => p.GetText().Contains("Fourth list") && ((Paragraph)p).IsListItem));
            }
            //ExEnd
        }
Пример #13
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            string filePath = dataDir + "MultiEncoded.csv";

            //Set Multi Encoded Property to True
            TxtLoadOptions options = new TxtLoadOptions();
            options.IsMultiEncoded = true;

            //Load the CSV file into Workbook
            Workbook workbook = new Workbook(filePath, options);

            //Save it in XLSX format
            workbook.Save( filePath + ".out.xlsx", SaveFormat.Xlsx);
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            string filePath = dataDir + "MultiEncoded.csv";

            // Set Multi Encoded Property to True
            TxtLoadOptions options = new TxtLoadOptions();

            options.IsMultiEncoded = true;

            // Load the CSV file into Workbook
            Workbook workbook = new Workbook(filePath, options);

            // Save it in XLSX format
            workbook.Save(filePath + ".out.xlsx", SaveFormat.Xlsx);
        }
Пример #15
0
        public static void DocumentTextDirection(string dataDir)
        {
            //ExStart:DocumentTextDirection
            TxtLoadOptions loadOptions = new TxtLoadOptions();

            loadOptions.DocumentDirection = DocumentDirection.Auto;

            Document doc = new Document(dataDir + "arabic.txt", loadOptions);

            Paragraph paragraph = doc.FirstSection.Body.FirstParagraph;

            Console.WriteLine(paragraph.ParagraphFormat.Bidi);

            dataDir = dataDir + "DocumentDirection_out.docx";
            doc.Save(dataDir);
            //ExEnd:DocumentTextDirection
            Console.WriteLine("\nFile saved at " + dataDir);
        }
Пример #16
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            string filePath = dataDir + "MultiEncoded.csv";

            //Set Multi Encoded Property to True
            TxtLoadOptions options = new TxtLoadOptions();

            options.IsMultiEncoded = true;

            //Load the CSV file into Workbook
            Workbook workbook = new Workbook(filePath, options);

            //Save it in XLSX format
            workbook.Save(filePath + ".out.xlsx", SaveFormat.Xlsx);
        }
        public void HandleSpacesOptions()
        {
            //ExStart:HandleSpacesOptions
            const string textDoc = "      Line 1 \n" +
                                   "    Line 2   \n" +
                                   " Line 3       ";

            TxtLoadOptions loadOptions = new TxtLoadOptions
            {
                LeadingSpacesOptions  = TxtLeadingSpacesOptions.Trim,
                TrailingSpacesOptions = TxtTrailingSpacesOptions.Trim
            };

            Document doc = new Document(new MemoryStream(Encoding.UTF8.GetBytes(textDoc)), loadOptions);

            doc.Save(ArtifactsDir + "WorkingWithTxtLoadOptions.HandleSpacesOptions.docx");
            //ExEnd:HandleSpacesOptions
        }
        public void DetectDocumentDirection()
        {
            //ExStart
            //ExFor:TxtLoadOptions.DocumentDirection
            //ExSummary:Shows how to detect document direction automatically.
            // Create a LoadOptions object and configure it to detect text direction automatically upon loading
            TxtLoadOptions loadOptions = new TxtLoadOptions();

            loadOptions.DocumentDirection = DocumentDirection.Auto;

            // Text like Hebrew/Arabic will be automatically detected as RTL
            Document doc = new Document(MyDir + "Hebrew text.txt", loadOptions);

            Assert.True(doc.FirstSection.Body.FirstParagraph.ParagraphFormat.Bidi);

            doc = new Document(MyDir + "English text.txt", loadOptions);

            Assert.False(doc.FirstSection.Body.FirstParagraph.ParagraphFormat.Bidi);
            //ExEnd
        }
        public void DetectNumberingWithWhitespaces()
        {
            //ExStart
            //ExFor:TxtLoadOptions.DetectNumberingWithWhitespaces
            //ExFor:TxtLoadOptions.TrailingSpacesOptions
            //ExFor:TxtLoadOptions.LeadingSpacesOptions
            //ExSummary:Shows how to load plain text as is.
            TxtLoadOptions loadOptions = new TxtLoadOptions
            {
                // If it sets to true Aspose.Words insert additional periods after numbers in the content.
                DetectNumberingWithWhitespaces = false,
                TrailingSpacesOptions          = TxtTrailingSpacesOptions.Preserve,
                LeadingSpacesOptions           = TxtLeadingSpacesOptions.Preserve
            };

            Document doc = new Document(MyDir + "TxtLoadOptions.DetectNumberingWithWhitespaces.txt", loadOptions);

            doc.Save(MyDir + @"\Artifacts\TxtLoadOptions.DetectNumberingWithWhitespaces.txt");
            //ExEnd
        }
Пример #20
0
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            //Output directory
            string outputDir = RunExamples.Get_OutputDirectory();

            // Set Multi Encoded Property to True
            TxtLoadOptions options = new TxtLoadOptions();

            options.IsMultiEncoded = true;

            // Load the CSV file into Workbook
            Workbook workbook = new Workbook(sourceDir + "sampleReadingCSVMultipleEncodings.csv", options);

            // Save it in XLSX format
            workbook.Save(outputDir + "outputReadingCSVMultipleEncodings.xlsx", SaveFormat.Xlsx);

            Console.WriteLine("ReadingCSVMultipleEncodings executed successfully.");
        }
        public static void Main()
        {
            // Initialize Text File's LoadFormat
            LoadFormat oLoadFormat = LoadFormat.CSV;

            // Initialize Text File's Load options
            TxtLoadOptions oTxtLoadOptions = new TxtLoadOptions(oLoadFormat);

            // Specify the separatot character
            oTxtLoadOptions.Separator = Convert.ToChar(",");

            // Specify the encoding scheme
            oTxtLoadOptions.Encoding = System.Text.Encoding.UTF8;

            // Set the flag to true for converting datetime data
            oTxtLoadOptions.ConvertDateTimeData = true;

            // Set the preferred parsers
            oTxtLoadOptions.PreferredParsers = new ICustomParser[] { new TextParser(), new DateParser() };

            // Initialize the workbook object by passing CSV file and text load options
            Workbook oExcelWorkBook = new Aspose.Cells.Workbook(sourceDir + "samplePreferredParser.csv", oTxtLoadOptions);

            // Get the first cell
            Cell oCell = oExcelWorkBook.Worksheets[0].Cells["A1"];

            // Display type of value
            Console.WriteLine("A1: " + oCell.Type.ToString() + " - " + oCell.DisplayStringValue);

            // Get the second cell
            oCell = oExcelWorkBook.Worksheets[0].Cells["B1"];

            // Display type of value
            Console.WriteLine("B1: " + oCell.Type.ToString() + " - " + oCell.DisplayStringValue);

            // Save the workbook to disc
            oExcelWorkBook.Save(outputDir + "outputsamplePreferredParser.xlsx");

            Console.WriteLine("OpeningCSVFilesWithPreferredParser executed successfully.\r\n");
        }
        public static void Run()
        {
            // ExStart:ImportCSVWithFormulas
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            TxtLoadOptions opts = new TxtLoadOptions();
            opts.Separator = ',';
            opts.HasFormula = true;

            // Load your CSV file with formulas in a Workbook object
            Workbook workbook = new Workbook(dataDir + "sample.csv", opts);

            // You can also import your CSV file like this
            // The code below is importing CSV file starting from cell D4
            Worksheet worksheet = workbook.Worksheets[0];
            worksheet.Cells.ImportCSV(dataDir + "sample.csv", opts, 3, 3);

            // Save your workbook in Xlsx format
            workbook.Save(dataDir + "output_out.xlsx");
            // ExEnd:ImportCSVWithFormulas
        }
Пример #23
0
        public static void Main(string[] args)
        {
            //ExStart:1
            // The path to the documents directory.
            string dataDir  = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            string filePath = dataDir + "Book11.csv";

            //Instantiate Text File's LoadOptions
            TxtLoadOptions txtLoadOptions = new TxtLoadOptions();

            //Specify the separator
            txtLoadOptions.Separator = Convert.ToChar(",");

            //Specify the encoding type
            txtLoadOptions.Encoding = System.Text.Encoding.UTF8;

            //Create a Workbook object and opening the file from its path
            Workbook wb = new Workbook(filePath, txtLoadOptions);

            //Save file
            wb.Save(dataDir + "output.txt");
            //ExEnd:1
        }
        public void DetectNumberingWithWhitespaces()
        {
            //ExStart:DetectNumberingWithWhitespaces
            // Create a plaintext document in the form of a string with parts that may be interpreted as lists.
            // Upon loading, the first three lists will always be detected by Aspose.Words,
            // and List objects will be created for them after loading.
            const string textDoc = "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";

            // The fourth list, with whitespace inbetween the list number and list item contents,
            // will only be detected as a list if "DetectNumberingWithWhitespaces" in a LoadOptions object is set to true,
            // to avoid paragraphs that start with numbers being mistakenly detected as lists.
            TxtLoadOptions loadOptions = new TxtLoadOptions {
                DetectNumberingWithWhitespaces = true
            };

            // Load the document while applying LoadOptions as a parameter and verify the result.
            Document doc = new Document(new MemoryStream(Encoding.UTF8.GetBytes(textDoc)), loadOptions);

            doc.Save(ArtifactsDir + "WorkingWithTxtLoadOptions.DetectNumberingWithWhitespaces.docx");
            //ExEnd:DetectNumberingWithWhitespaces
        }
Пример #25
0
        public static void Run()
        {
            // ExStart:ImportCSVWithFormulas
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            TxtLoadOptions opts = new TxtLoadOptions();

            opts.Separator  = ',';
            opts.HasFormula = true;

            // Load your CSV file with formulas in a Workbook object
            Workbook workbook = new Workbook(dataDir + "sample.csv", opts);

            // You can also import your CSV file like this
            // The code below is importing CSV file starting from cell D4
            Worksheet worksheet = workbook.Worksheets[0];

            worksheet.Cells.ImportCSV(dataDir + "sample.csv", opts, 3, 3);

            // Save your workbook in Xlsx format
            workbook.Save(dataDir + "output_out.xlsx");
            // ExEnd:ImportCSVWithFormulas
        }
        public void TrailSpaces(TxtLeadingSpacesOptions txtLeadingSpacesOptions, TxtTrailingSpacesOptions txtTrailingSpacesOptions)
        {
            //ExStart
            //ExFor:TxtLoadOptions.TrailingSpacesOptions
            //ExFor:TxtLoadOptions.LeadingSpacesOptions
            //ExFor:TxtTrailingSpacesOptions
            //ExFor:TxtLeadingSpacesOptions
            //ExSummary: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.LeadingSpacesOptions = 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.TrailingSpacesOptions = txtTrailingSpacesOptions;

            Document            doc        = new Document(new MemoryStream(Encoding.UTF8.GetBytes(textDoc)), loadOptions);
            ParagraphCollection paragraphs = doc.FirstSection.Body.Paragraphs;

            switch (txtLeadingSpacesOptions)
            {
            case TxtLeadingSpacesOptions.ConvertToIndent:
                Assert.AreEqual(37.8d, paragraphs[0].ParagraphFormat.FirstLineIndent);
                Assert.AreEqual(25.2d, paragraphs[1].ParagraphFormat.FirstLineIndent);
                Assert.AreEqual(6.3d, paragraphs[2].ParagraphFormat.FirstLineIndent);

                Assert.True(paragraphs[0].GetText().StartsWith("Line 1"));
                Assert.True(paragraphs[1].GetText().StartsWith("Line 2"));
                Assert.True(paragraphs[2].GetText().StartsWith("Line 3"));
                break;

            case TxtLeadingSpacesOptions.Preserve:
                Assert.True(paragraphs.All(p => ((Paragraph)p).ParagraphFormat.FirstLineIndent == 0.0d));

                Assert.True(paragraphs[0].GetText().StartsWith("      Line 1"));
                Assert.True(paragraphs[1].GetText().StartsWith("    Line 2"));
                Assert.True(paragraphs[2].GetText().StartsWith(" Line 3"));
                break;

            case TxtLeadingSpacesOptions.Trim:
                Assert.True(paragraphs.All(p => ((Paragraph)p).ParagraphFormat.FirstLineIndent == 0.0d));

                Assert.True(paragraphs[0].GetText().StartsWith("Line 1"));
                Assert.True(paragraphs[1].GetText().StartsWith("Line 2"));
                Assert.True(paragraphs[2].GetText().StartsWith("Line 3"));
                break;
            }

            switch (txtTrailingSpacesOptions)
            {
            case TxtTrailingSpacesOptions.Preserve:
                Assert.True(paragraphs[0].GetText().EndsWith("Line 1 \r"));
                Assert.True(paragraphs[1].GetText().EndsWith("Line 2   \r"));
                Assert.True(paragraphs[2].GetText().EndsWith("Line 3       \f"));
                break;

            case TxtTrailingSpacesOptions.Trim:
                Assert.True(paragraphs[0].GetText().EndsWith("Line 1\r"));
                Assert.True(paragraphs[1].GetText().EndsWith("Line 2\r"));
                Assert.True(paragraphs[2].GetText().EndsWith("Line 3\f"));
                break;
            }
            //ExEnd
        }
        public void TrailSpaces(TxtLeadingSpacesOptions txtLeadingSpacesOptions, TxtTrailingSpacesOptions txtTrailingSpacesOptions)
        {
            //ExStart
            //ExFor:TxtLoadOptions.TrailingSpacesOptions
            //ExFor:TxtLoadOptions.LeadingSpacesOptions
            //ExFor:TxtTrailingSpacesOptions
            //ExFor:TxtLeadingSpacesOptions
            //ExSummary:Shows how to trim whitespace when loading plaintext documents.
            string textDoc = "      Line 1 \n" +
                             "    Line 2   \n" +
                             " Line 3       ";

            TxtLoadOptions loadOptions = new TxtLoadOptions
            {
                LeadingSpacesOptions  = txtLeadingSpacesOptions,
                TrailingSpacesOptions = txtTrailingSpacesOptions
            };

            // Load the document while applying LoadOptions as a parameter and verify the result
            Document doc = new Document(new MemoryStream(Encoding.UTF8.GetBytes(textDoc)), loadOptions);

            ParagraphCollection paragraphs = doc.FirstSection.Body.Paragraphs;

            switch (txtLeadingSpacesOptions)
            {
            case TxtLeadingSpacesOptions.ConvertToIndent:
                Assert.AreEqual(37.8d, paragraphs[0].ParagraphFormat.FirstLineIndent);
                Assert.AreEqual(25.2d, paragraphs[1].ParagraphFormat.FirstLineIndent);
                Assert.AreEqual(6.3d, paragraphs[2].ParagraphFormat.FirstLineIndent);

                Assert.True(paragraphs[0].GetText().StartsWith("Line 1"));
                Assert.True(paragraphs[1].GetText().StartsWith("Line 2"));
                Assert.True(paragraphs[2].GetText().StartsWith("Line 3"));
                break;

            case TxtLeadingSpacesOptions.Preserve:
                Assert.True(paragraphs.All(p => ((Paragraph)p).ParagraphFormat.FirstLineIndent == 0.0d));

                Assert.True(paragraphs[0].GetText().StartsWith("      Line 1"));
                Assert.True(paragraphs[1].GetText().StartsWith("    Line 2"));
                Assert.True(paragraphs[2].GetText().StartsWith(" Line 3"));
                break;

            case TxtLeadingSpacesOptions.Trim:
                Assert.True(paragraphs.All(p => ((Paragraph)p).ParagraphFormat.FirstLineIndent == 0.0d));

                Assert.True(paragraphs[0].GetText().StartsWith("Line 1"));
                Assert.True(paragraphs[1].GetText().StartsWith("Line 2"));
                Assert.True(paragraphs[2].GetText().StartsWith("Line 3"));
                break;
            }

            switch (txtTrailingSpacesOptions)
            {
            case TxtTrailingSpacesOptions.Preserve:
                Assert.True(paragraphs[0].GetText().EndsWith("Line 1 \r"));
                Assert.True(paragraphs[1].GetText().EndsWith("Line 2   \r"));
                Assert.True(paragraphs[2].GetText().EndsWith("Line 3       \f"));
                break;

            case TxtTrailingSpacesOptions.Trim:
                Assert.True(paragraphs[0].GetText().EndsWith("Line 1\r"));
                Assert.True(paragraphs[1].GetText().EndsWith("Line 2\r"));
                Assert.True(paragraphs[2].GetText().EndsWith("Line 3\f"));
                break;
            }
            //ExEnd
        }