From 26eb03d5df62c1631ed3e332733fb6adf4618a7e Mon Sep 17 00:00:00 2001 From: Suriya-Balamurugan Date: Thu, 21 Nov 2024 10:53:18 +0530 Subject: [PATCH] Added README files for DocIO interactive sample browser --- .../Replace-content-with-body-part/README.md | 53 +++++++ .../.NET/Compare-Word-documents/README.md | 44 ++++++ .../.NET/Fill-form-in-Word-document/README.md | 121 ++++++++++++++++ .../.NET/Replace-misspelled-word/README.md | 39 ++++++ .../.NET/Convert-HTML-to-Word/README.md | 37 +++++ .../.NET/Convert-Word-to-HTML/README.md | 37 +++++ .../README.md | 127 +++++++++++++++++ .../.NET/Convert-Markdown-to-Word/README.md | 38 ++++++ .../README.md | 39 ++++++ .../.NET/Add-table-of-contents/README.md | 74 ++++++++++ .../.NET/Apply-table-formatting/README.md | 78 +++++++++++ .../.NET/Convert-Word-to-text-file/README.md | 37 +++++ .../Merge-documents-in-new-page/README.md | 46 +++++++ .../.NET/Split-by-bookmark/README.md | 49 +++++++ .../.NET/Split-by-heading/README.md | 129 ++++++++++++++++++ .../.NET/Split-by-placeholder-text/README.md | 99 ++++++++++++++ .../.NET/Split-by-section/README.md | 48 +++++++ .../First-page-of-Word-to-image/README.md | 46 +++++++ .../.NET/Convert-Word-to-Markdown/README.md | 38 ++++++ .../Convert-Word-document-to-PDF/README.md | 49 +++++++ .../README.md | 48 +++++++ .../.NET/PDF-conformance-level/README.md | 48 +++++++ 22 files changed, 1324 insertions(+) create mode 100644 Bookmarks/Replace-content-with-body-part/.NET/Replace-content-with-body-part/README.md create mode 100644 Compare-Word-documents/Compare-two-Word-documents/.NET/Compare-Word-documents/README.md create mode 100644 Content-Controls/Fill-form-in-Word-document/.NET/Fill-form-in-Word-document/README.md create mode 100644 Find-and-Replace/Replace-misspelled-word/.NET/Replace-misspelled-word/README.md create mode 100644 HTML-conversions/Convert-HTML-to-Word/.NET/Convert-HTML-to-Word/README.md create mode 100644 HTML-conversions/Convert-Word-to-HTML/.NET/Convert-Word-to-HTML/README.md create mode 100644 Mail-Merge/Mail-merge-with-implicit-relational-data/.NET/Mail-merge-with-implicit-relational-data/README.md create mode 100644 Markdown-to-Word-conversion/Convert-Markdown-to-Word/.NET/Convert-Markdown-to-Word/README.md create mode 100644 Security/Encrypt-Word-document-with-password/.NET/Encrypt-Word-document-with-password/README.md create mode 100644 Table-Of-Contents/Add-table-of-contents/.NET/Add-table-of-contents/README.md create mode 100644 Tables/Apply-table-formatting/.NET/Apply-table-formatting/README.md create mode 100644 Text-file-conversion/Convert-Word-to-text-file/.NET/Convert-Word-to-text-file/README.md create mode 100644 Word-document/Merge-documents-in-new-page/.NET/Merge-documents-in-new-page/README.md create mode 100644 Word-document/Split-by-bookmark/.NET/Split-by-bookmark/README.md create mode 100644 Word-document/Split-by-heading/.NET/Split-by-heading/README.md create mode 100644 Word-document/Split-by-placeholder-text/.NET/Split-by-placeholder-text/README.md create mode 100644 Word-document/Split-by-section/.NET/Split-by-section/README.md create mode 100644 Word-to-Image-conversion/First-page-of-Word-to-image/.NET/First-page-of-Word-to-image/README.md create mode 100644 Word-to-Markdown-conversion/Convert-Word-to-Markdown/.NET/Convert-Word-to-Markdown/README.md create mode 100644 Word-to-PDF-Conversion/Convert-Word-document-to-PDF/.NET/Convert-Word-document-to-PDF/README.md create mode 100644 Word-to-PDF-Conversion/Convert-Word-into-accessible-PDF/.NET/Convert-Word-into-accessible-PDF/README.md create mode 100644 Word-to-PDF-Conversion/PDF-conformance-level/.NET/PDF-conformance-level/README.md diff --git a/Bookmarks/Replace-content-with-body-part/.NET/Replace-content-with-body-part/README.md b/Bookmarks/Replace-content-with-body-part/.NET/Replace-content-with-body-part/README.md new file mode 100644 index 00000000..8adfbeeb --- /dev/null +++ b/Bookmarks/Replace-content-with-body-part/.NET/Replace-content-with-body-part/README.md @@ -0,0 +1,53 @@ +# Replace bookmark content in a Word document using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **replace bookmark content in a Word document** using C#. + +## Steps to replace bookmark content programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to replace bookmark content in the Word document. + +```csharp +using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +{ + //Opens an existing Word document. + using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic)) + { + //Creates the bookmark navigator instance to access the bookmark. + BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document); + //Moves the virtual cursor to the location before the end of the bookmark "Northwind". + bookmarkNavigator.MoveToBookmark("Northwind"); + //Gets the bookmark content. + TextBodyPart textBodyPart = bookmarkNavigator.GetBookmarkContent(); + document.AddSection(); + IWParagraph paragraph = document.LastSection.AddParagraph(); + paragraph.AppendText("Northwind Database is a set of tables containing data fitted into predefined categories."); + //Adds the new bookmark into Word document. + paragraph.AppendBookmarkStart("bookmark_empty"); + paragraph.AppendBookmarkEnd("bookmark_empty"); + //Moves the virtual cursor to the location before the end of the bookmark "bookmark_empty". + bookmarkNavigator.MoveToBookmark("bookmark_empty"); + //Replaces the bookmark content with text body part. + bookmarkNavigator.ReplaceBookmarkContent(textBodyPart); + //Creates file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputFileStream, FormatType.Docx); + } + } +} +``` + +More information about the bookmarks can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-bookmarks) section. \ No newline at end of file diff --git a/Compare-Word-documents/Compare-two-Word-documents/.NET/Compare-Word-documents/README.md b/Compare-Word-documents/Compare-two-Word-documents/.NET/Compare-Word-documents/README.md new file mode 100644 index 00000000..dada0315 --- /dev/null +++ b/Compare-Word-documents/Compare-two-Word-documents/.NET/Compare-Word-documents/README.md @@ -0,0 +1,44 @@ +# Compare Word documents using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **compare Word documents** using C#. + +## Steps to compare Word documents programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +``` + +Step 4: Add the following code snippet in Program.cs file to compare Word documents. + +```csharp +//Loads the original document. +using (FileStream originalDocumentStreamPath = new FileStream(Path.GetFullPath(@"Data/OriginalDocument.docx"), FileMode.Open, FileAccess.Read)) +{ + using (WordDocument originalDocument = new WordDocument(originalDocumentStreamPath, FormatType.Docx)) + { + //Loads the revised document + using (FileStream revisedDocumentStreamPath = new FileStream(Path.GetFullPath(@"Data/RevisedDocument.docx"), FileMode.Open, FileAccess.Read)) + { + using (WordDocument revisedDocument = new WordDocument(revisedDocumentStreamPath, FormatType.Docx)) + { + //Compare the original and revised Word documents. + originalDocument.Compare(revisedDocument); + //Save the Word document. + using (FileStream fileStreamOutput = File.Create(Path.GetFullPath("Output/Output.docx"))) + { + originalDocument.Save(fileStreamOutput, FormatType.Docx); + } + } + } + } +} +``` + +More information about comparing Word document can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/word-document/compare-word-documents) section. \ No newline at end of file diff --git a/Content-Controls/Fill-form-in-Word-document/.NET/Fill-form-in-Word-document/README.md b/Content-Controls/Fill-form-in-Word-document/.NET/Fill-form-in-Word-document/README.md new file mode 100644 index 00000000..900b1155 --- /dev/null +++ b/Content-Controls/Fill-form-in-Word-document/.NET/Fill-form-in-Word-document/README.md @@ -0,0 +1,121 @@ +# Form filling in Word document using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **fill forms in a Word document** using C#. + +## Steps to fill forms programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to fill forms in the Word document. + +```csharp +using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +{ + //Creates a new Word document. + using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic)) + { + IWSection sec = document.LastSection; + InlineContentControl inlineCC; + InlineContentControl dropDownCC; + WTable table1 = sec.Tables[1] as WTable; + WTableRow row1 = table1.Rows[1]; + + #region General Information + //Fill the name. + WParagraph cellPara1 = row1.Cells[0].ChildEntities[1] as WParagraph; + inlineCC = cellPara1.ChildEntities.LastItem as InlineContentControl; + WTextRange text = new WTextRange(document); + text.ApplyCharacterFormat(inlineCC.BreakCharacterFormat); + text.Text = "Steve Jobs"; + inlineCC.ParagraphItems.Add(text); + //Fill the date of birth. + cellPara1 = row1.Cells[0].ChildEntities[3] as WParagraph; + inlineCC = cellPara1.ChildEntities.LastItem as InlineContentControl; + text = new WTextRange(document); + text.ApplyCharacterFormat(inlineCC.BreakCharacterFormat); + text.Text = "06/01/1994"; + inlineCC.ParagraphItems.Add(text); + //Fill the address. + cellPara1 = row1.Cells[0].ChildEntities[5] as WParagraph; + inlineCC = cellPara1.ChildEntities.LastItem as InlineContentControl; + text = new WTextRange(document); + text.ApplyCharacterFormat(inlineCC.BreakCharacterFormat); + text.Text = "2501 Aerial Center Parkway."; + inlineCC.ParagraphItems.Add(text); + text = new WTextRange(document); + text.ApplyCharacterFormat(inlineCC.BreakCharacterFormat); + text.Text = "Morrisville, NC 27560."; + inlineCC.ParagraphItems.Add(text); + text = new WTextRange(document); + text.ApplyCharacterFormat(inlineCC.BreakCharacterFormat); + text.Text = "USA."; + inlineCC.ParagraphItems.Add(text); + //Fill the phone no. + cellPara1 = row1.Cells[0].ChildEntities[7] as WParagraph; + inlineCC = cellPara1.ChildEntities.LastItem as InlineContentControl; + text = new WTextRange(document); + text.ApplyCharacterFormat(inlineCC.BreakCharacterFormat); + text.Text = "+1 919.481.1974"; + inlineCC.ParagraphItems.Add(text); + //Fill the email id. + cellPara1 = row1.Cells[0].ChildEntities[9] as WParagraph; + inlineCC = cellPara1.ChildEntities.LastItem as InlineContentControl; + text = new WTextRange(document); + text.ApplyCharacterFormat(inlineCC.BreakCharacterFormat); + text.Text = "steve123@email.com"; + inlineCC.ParagraphItems.Add(text); + #endregion + + #region Educational Information + table1 = sec.Tables[2] as WTable; + row1 = table1.Rows[1]; + //Fill the education type. + cellPara1 = row1.Cells[0].ChildEntities[1] as WParagraph; + dropDownCC = cellPara1.ChildEntities.LastItem as InlineContentControl; + text = new WTextRange(document); + text.ApplyCharacterFormat(dropDownCC.BreakCharacterFormat); + text.Text = dropDownCC.ContentControlProperties.ContentControlListItems[1].DisplayText; + dropDownCC.ParagraphItems.Add(text); + //Fill the university. + cellPara1 = row1.Cells[0].ChildEntities[3] as WParagraph; + inlineCC = cellPara1.ChildEntities.LastItem as InlineContentControl; + text = new WTextRange(document); + text.ApplyCharacterFormat(dropDownCC.BreakCharacterFormat); + text.Text = "Michigan University"; + inlineCC.ParagraphItems.Add(text); + //Fill the C# experience level. + cellPara1 = row1.Cells[0].ChildEntities[7] as WParagraph; + dropDownCC = cellPara1.ChildEntities.LastItem as InlineContentControl; + text = new WTextRange(document); + text.ApplyCharacterFormat(dropDownCC.BreakCharacterFormat); + text.Text = dropDownCC.ContentControlProperties.ContentControlListItems[2].DisplayText; + dropDownCC.ParagraphItems.Add(text); + //Fill the VB experience level. + cellPara1 = row1.Cells[0].ChildEntities[9] as WParagraph; + dropDownCC = cellPara1.ChildEntities.LastItem as InlineContentControl; + text = new WTextRange(document); + text.ApplyCharacterFormat(dropDownCC.BreakCharacterFormat); + text.Text = dropDownCC.ContentControlProperties.ContentControlListItems[1].DisplayText; + dropDownCC.ParagraphItems.Add(text); + #endregion + //Creates file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputFileStream, FormatType.Docx); + } + } +} +``` + +More information about the content controls can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-content-controls) section. \ No newline at end of file diff --git a/Find-and-Replace/Replace-misspelled-word/.NET/Replace-misspelled-word/README.md b/Find-and-Replace/Replace-misspelled-word/.NET/Replace-misspelled-word/README.md new file mode 100644 index 00000000..f217b221 --- /dev/null +++ b/Find-and-Replace/Replace-misspelled-word/.NET/Replace-misspelled-word/README.md @@ -0,0 +1,39 @@ +# Find and replace text in Word document using C# + +The Syncfusion [. NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **find and replace text in a Word document** using C#. + +## Steps to find and replace text programmatically + +Step 1: Create a new . NET Core console application project. + +Step 2: Install the [Syncfusion. DocIO. Net. Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to find and replace text in the Word document. + +```csharp +using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +{ + //Opens an existing Word document. + using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)) + { + //Finds all occurrences of a misspelled word and replaces with properly spelled word. + document.Replace("Cyles", "Cycles", true, true); + //Creates file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputFileStream, FormatType.Docx); + } + } +} +``` + +More information about find and replace functionality can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-find-and-replace) section. diff --git a/HTML-conversions/Convert-HTML-to-Word/.NET/Convert-HTML-to-Word/README.md b/HTML-conversions/Convert-HTML-to-Word/.NET/Convert-HTML-to-Word/README.md new file mode 100644 index 00000000..f0504fef --- /dev/null +++ b/HTML-conversions/Convert-HTML-to-Word/.NET/Convert-HTML-to-Word/README.md @@ -0,0 +1,37 @@ +# Convert HTML to Word document using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, edit, and convert Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **convert HTML to a Word document** using C#. + +## Steps to convert HTML to Word programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to convert HTML to a Word document. + +```csharp +//Loads an existing Word document into DocIO instance. +using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +{ + using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)) + { + //Creates file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/WordToHtml.html"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputFileStream, FormatType.Html); + } + } +} +``` + +More information about HTML to Word conversion and vice versa can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/html) section. \ No newline at end of file diff --git a/HTML-conversions/Convert-Word-to-HTML/.NET/Convert-Word-to-HTML/README.md b/HTML-conversions/Convert-Word-to-HTML/.NET/Convert-Word-to-HTML/README.md new file mode 100644 index 00000000..778d9a23 --- /dev/null +++ b/HTML-conversions/Convert-Word-to-HTML/.NET/Convert-Word-to-HTML/README.md @@ -0,0 +1,37 @@ +# Convert Word document to HTML using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, edit, and convert Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **convert a Word document to HTML** using C#. + +## Steps to convert Word to HTML programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to convert a Word document to HTML. + +```csharp +//Loads an existing Word document into DocIO instance. +using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +{ + using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)) + { + //Creates file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/WordToHtml.html"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputFileStream, FormatType.Html); + } + } +} +``` + +More information about Word to HTML conversion and vice versa can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/html) section. \ No newline at end of file diff --git a/Mail-Merge/Mail-merge-with-implicit-relational-data/.NET/Mail-merge-with-implicit-relational-data/README.md b/Mail-Merge/Mail-merge-with-implicit-relational-data/.NET/Mail-merge-with-implicit-relational-data/README.md new file mode 100644 index 00000000..23c90327 --- /dev/null +++ b/Mail-Merge/Mail-merge-with-implicit-relational-data/.NET/Mail-merge-with-implicit-relational-data/README.md @@ -0,0 +1,127 @@ +# Mail merge in a Word document using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **perform mail merge operations in a Word document** using C#. + +## Steps to perform mail merge programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.Collections.Generic; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to perform mail merge in the Word document. + +```csharp +using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.ReadWrite)) +{ + //Opens the template document. + using (WordDocument document = new WordDocument(fileStream, FormatType.Docx)) + { + //Gets the organization details as “IEnumerable” collection. + List organizationList = GetOrganizations(); + //Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection. + MailMergeDataTable dataTable = new MailMergeDataTable("Organizations", organizationList); + //Performs Mail merge. + document.MailMerge.ExecuteNestedGroup(dataTable); + //Creates file stream. + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputStream, FormatType.Docx); + } + } +} +``` + +Step 5: Add the helper method to get data to perform mail merge. + +```csharp +/// +/// Get the data to perform mail merge. +/// +public static List GetOrganizations() +{ + //Creates Employee details. + List employees = new List(); + employees.Add(new EmployeeDetails("Thomas Hardy", "1001", "05/27/1996")); + employees.Add(new EmployeeDetails("Maria Anders", "1002", "04/10/1998")); + //Creates Departments details. + List departments = new List(); + departments.Add(new DepartmentDetails("Marketing", "Nancy Davolio", employees)); + + employees = new List(); + employees.Add(new EmployeeDetails("Elizabeth Lincoln", "1003", "05/15/1996")); + employees.Add(new EmployeeDetails("Antonio Moreno", "1004", "04/22/1996")); + departments.Add(new DepartmentDetails("Production", "Andrew Fuller", employees)); + //Creates organization details. + List organizations = new List(); + organizations.Add(new Organization("UK Office", "120 Hanover Sq.", "London", "WX1 6LT", "UK", departments)); + return organizations; +} +``` + +Step 6: Add the helper class to maintain organization details. + +```csharp +/// +/// Represents a class to maintain organization details. +/// +public class Organization +{ + public string BranchName { get; set; } + public string Address { get; set; } + public string City { get; set; } + public string ZipCode { get; set; } + public string Country { get; set; } + public List Departments { get; set; } + public Organization(string branchName, string address, string city, string zipcode, string country, List departments) + { + BranchName = branchName; + Address = address; + City = city; + ZipCode = zipcode; + Country = country; + Departments = departments; + } +} +/// +/// Represents a class to maintain department details. +/// +public class DepartmentDetails +{ + public string DepartmentName { get; set; } + public string Supervisor { get; set; } + public List Employees { get; set; } + public DepartmentDetails(string departmentName, string supervisor, List employees) + { + DepartmentName = departmentName; + Supervisor = supervisor; + Employees = employees; + } +} +/// +/// Represents a class to maintain employee details. +/// +public class EmployeeDetails +{ + public string EmployeeName { get; set; } + public string EmployeeID { get; set; } + public string JoinedDate { get; set; } + public EmployeeDetails(string employeeName, string employeeID, string joinedDate) + { + EmployeeName = employeeName; + EmployeeID = employeeID; + JoinedDate = joinedDate; + } +} +``` + +More information about the mail merge can be found in this [documentation](https://help.syncfusion.com/file-formats/docio/working-with-mailmerge) section. \ No newline at end of file diff --git a/Markdown-to-Word-conversion/Convert-Markdown-to-Word/.NET/Convert-Markdown-to-Word/README.md b/Markdown-to-Word-conversion/Convert-Markdown-to-Word/.NET/Convert-Markdown-to-Word/README.md new file mode 100644 index 00000000..7ebd30e1 --- /dev/null +++ b/Markdown-to-Word-conversion/Convert-Markdown-to-Word/.NET/Convert-Markdown-to-Word/README.md @@ -0,0 +1,38 @@ +# Convert Markdown to Word document using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, edit, and convert Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **convert Markdown to a Word document** using C#. + +## Steps to convert Markdown to Word programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to convert Markdown to a Word document. + +```csharp +//Open a file as a stream. +using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.md"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +{ + //Load the file stream into a Markdown file. + using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Markdown)) + { + //Create a file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/MarkdownToWord.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Save a Word document to the file stream. + document.Save(outputFileStream, FormatType.Docx); + } + } +} +``` + +More information about Markdown to Word conversion can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/convert-markdown-to-word-document-in-csharp) section. \ No newline at end of file diff --git a/Security/Encrypt-Word-document-with-password/.NET/Encrypt-Word-document-with-password/README.md b/Security/Encrypt-Word-document-with-password/.NET/Encrypt-Word-document-with-password/README.md new file mode 100644 index 00000000..ce7af87c --- /dev/null +++ b/Security/Encrypt-Word-document-with-password/.NET/Encrypt-Word-document-with-password/README.md @@ -0,0 +1,39 @@ +# Encrypt Word document using C# + +The Syncfusion [. NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **encrypt Word documents** using C#. + +## Steps to encrypt a Word document programmatically + +Step 1: Create a new . NET Core console application project. + +Step 2: Install the [Syncfusion. DocIO. Net. Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to encrypt a Word document. + +```csharp +using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.ReadWrite)) +{ + //Opens the template document. + using (WordDocument document = new WordDocument(fileStream, FormatType.Docx)) + { + //Encrypts the Word document with a password. + document.EncryptDocument("syncfusion"); + //Creates file stream. + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputStream, FormatType.Docx); + } + } +} +``` + +More information about the encrypt and decrypt options can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-security) section. \ No newline at end of file diff --git a/Table-Of-Contents/Add-table-of-contents/.NET/Add-table-of-contents/README.md b/Table-Of-Contents/Add-table-of-contents/.NET/Add-table-of-contents/README.md new file mode 100644 index 00000000..c6addd23 --- /dev/null +++ b/Table-Of-Contents/Add-table-of-contents/.NET/Add-table-of-contents/README.md @@ -0,0 +1,74 @@ +# Add and update Table of Contents in Word document using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **add and update a Table of Contents (TOC) in a Word document** using C#. + +## Steps to add and update Table of Contents (TOC) programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIORenderer.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIORenderer.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIORenderer; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to add and update TOC in the Word document. + +```csharp +//Creates a new Word document. +using (WordDocument document = new WordDocument()) +{ + //Adds the section into the Word document. + IWSection section = document.AddSection(); + string paraText = "AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company."; + //Adds the paragraph into the created section. + IWParagraph paragraph = section.AddParagraph(); + //Appends the TOC field with LowerHeadingLevel and UpperHeadingLevel to determines the TOC entries. + paragraph.AppendTOC(1, 3); + //Adds the section into the Word document. + section = document.AddSection(); + //Adds the paragraph into the created section. + paragraph = section.AddParagraph(); + //Adds the text for the headings. + paragraph.AppendText("First Chapter"); + //Sets a built-in heading style. + paragraph.ApplyStyle(BuiltinStyle.Heading1); + //Adds the text into the paragraph. + section.AddParagraph().AppendText(paraText); + //Adds the section into the Word document. + section = document.AddSection(); + //Adds the paragraph into the created section. + paragraph = section.AddParagraph(); + //Adds the text for the headings. + paragraph.AppendText("Second Chapter"); + //Sets a built-in heading style. + paragraph.ApplyStyle(BuiltinStyle.Heading2); + //Adds the text into the paragraph. + section.AddParagraph().AppendText(paraText); + //Adds the section into the Word document. + section = document.AddSection(); + //Adds the paragraph into the created section + paragraph = section.AddParagraph(); + //Adds the text into the headings. + paragraph.AppendText("Third Chapter"); + //Sets a built-in heading style. + paragraph.ApplyStyle(BuiltinStyle.Heading3); + //Adds the text into the paragraph. + section.AddParagraph().AppendText(paraText); + //Updates the table of contents. + document.UpdateTableOfContents(); + //Creates file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputFileStream, FormatType.Docx); + } +} +``` + +More information about the Table of Contents can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-table-of-contents) section. \ No newline at end of file diff --git a/Tables/Apply-table-formatting/.NET/Apply-table-formatting/README.md b/Tables/Apply-table-formatting/.NET/Apply-table-formatting/README.md new file mode 100644 index 00000000..90db5183 --- /dev/null +++ b/Tables/Apply-table-formatting/.NET/Apply-table-formatting/README.md @@ -0,0 +1,78 @@ +# Format table in a Word document using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **format tables in a Word document** using C#. + +## Steps to format a table programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.Drawing; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to format a table in the Word document. + +```csharp +using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +{ + //Creates an instance of WordDocument class (Empty Word Document). + using (WordDocument document = new WordDocument()) + { + //Opens an existing Word document into DocIO instance. + document.Open(fileStreamPath, FormatType.Docx); + //Accesses the instance of the first section in the Word document. + WSection section = document.Sections[0]; + //Accesses the instance of the first table in the section. + WTable table = section.Tables[0] as WTable; + //Specifies the title for the table. + table.Title = "PriceDetails"; + //Specifies the description of the table. + table.Description = "This table shows the price details of various fruits"; + //Specifies the left indent of the table. + table.IndentFromLeft = 50; + //Specifies the background color of the table. + table.TableFormat.BackColor = Color.FromArgb(192, 192, 192); + //Specifies the horizontal alignment of the table. + table.TableFormat.HorizontalAlignment = RowAlignment.Left; + //Specifies the left, right, top and bottom padding of all the cells in the table. + table.TableFormat.Paddings.All = 10; + //Specifies the auto resize of table to automatically resize all cell width based on its content. + table.TableFormat.IsAutoResized = true; + //Specifies the table top, bottom, left and right border line width. + table.TableFormat.Borders.LineWidth = 2f; + //Specifies the table horizontal border line width. + table.TableFormat.Borders.Horizontal.LineWidth = 2f; + //Specifies the table vertical border line width. + table.TableFormat.Borders.Vertical.LineWidth = 2f; + //Specifies the tables top, bottom, left and right border color. + table.TableFormat.Borders.Color = Color.Red; + //Specifies the table Horizontal border color. + table.TableFormat.Borders.Horizontal.Color = Color.Red; + //Specifies the table vertical border color. + table.TableFormat.Borders.Vertical.Color = Color.Red; + //Specifies the table borders border type. + table.TableFormat.Borders.BorderType = BorderStyle.Double; + //Accesses the instance of the first row in the table. + WTableRow row = table.Rows[0]; + //Specifies the row height. + row.Height = 20; + //Specifies the row height type. + row.HeightType = TableRowHeightType.AtLeast; + //Creates file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputFileStream, FormatType.Docx); + } + } +} +``` + +More information about the table formatting can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-tables#apply-formatting-to-table-row-and-cell) section. \ No newline at end of file diff --git a/Text-file-conversion/Convert-Word-to-text-file/.NET/Convert-Word-to-text-file/README.md b/Text-file-conversion/Convert-Word-to-text-file/.NET/Convert-Word-to-text-file/README.md new file mode 100644 index 00000000..75b616ff --- /dev/null +++ b/Text-file-conversion/Convert-Word-to-text-file/.NET/Convert-Word-to-text-file/README.md @@ -0,0 +1,37 @@ +# Convert Word document to Text using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, edit, and convert Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **convert a Word document to Text** using C#. + +## Steps to convert Word to Text programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to convert a Word document to text. + +```csharp +//Loads an existing Word document into DocIO instance. +using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +{ + using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)) + { + //Creates file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/WordToText.txt"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputFileStream, FormatType.Txt); + } + } +} +``` + +More information about Word to Text conversion and vice versa can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/text) section. \ No newline at end of file diff --git a/Word-document/Merge-documents-in-new-page/.NET/Merge-documents-in-new-page/README.md b/Word-document/Merge-documents-in-new-page/.NET/Merge-documents-in-new-page/README.md new file mode 100644 index 00000000..61fecbf1 --- /dev/null +++ b/Word-document/Merge-documents-in-new-page/.NET/Merge-documents-in-new-page/README.md @@ -0,0 +1,46 @@ +# Merge Word documents using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **merge Word documents** using C#. + +## Steps to merge Word documents programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to merge Word documents. + +```csharp +using (FileStream sourceStreamPath = new FileStream(Path.GetFullPath(@"Data/SourceDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +{ + //Opens an source document from file system through constructor of WordDocument class. + using (WordDocument sourceDocument = new WordDocument(sourceStreamPath, FormatType.Automatic)) + { + using (FileStream destinationStreamPath = new FileStream(Path.GetFullPath(@"Data/DestinationDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + //Opens the destination document. + using (WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Automatic)) + { + //Imports the contents of source document at the end of destination document. + destinationDocument.ImportContent(sourceDocument, ImportOptions.UseDestinationStyles); + //Creates file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + destinationDocument.Save(outputFileStream, FormatType.Docx); + } + } + } + } +} +``` + +More information about merging Word documents can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/word-document/merging-word-documents) section. \ No newline at end of file diff --git a/Word-document/Split-by-bookmark/.NET/Split-by-bookmark/README.md b/Word-document/Split-by-bookmark/.NET/Split-by-bookmark/README.md new file mode 100644 index 00000000..5c07b2c3 --- /dev/null +++ b/Word-document/Split-by-bookmark/.NET/Split-by-bookmark/README.md @@ -0,0 +1,49 @@ +# Split Word document by Bookmarks using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) empowers you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **split a Word document by bookmarks** using C#. + +## Steps to split Word document by bookmarks programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to split Word document by bookmarks. + +```csharp +//Load an existing Word document. +FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)) +{ + //Create the bookmark navigator instance to access the bookmark. + BookmarksNavigator bookmarksNavigator = new BookmarksNavigator(document); + BookmarkCollection bookmarkCollection = document.Bookmarks; + //Iterate each bookmark in Word document. + foreach (Bookmark bookmark in bookmarkCollection) + { + //Move the virtual cursor to the location before the end of the bookmark. + bookmarksNavigator.MoveToBookmark(bookmark.Name); + //Get the bookmark content as WordDocumentPart. + WordDocumentPart documentPart = bookmarksNavigator.GetContent(); + //Save the WordDocumentPart as separate Word document + using (WordDocument newDocument = documentPart.GetAsWordDocument()) + { + //Save the Word document to file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/" + bookmark.Name + ".docx"), FileMode.Create, FileAccess.ReadWrite)) + { + newDocument.Save(outputFileStream, FormatType.Docx); + } + } + } +} +``` + +More information about splitting a Word document can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/word-document/split-word-documents) section. \ No newline at end of file diff --git a/Word-document/Split-by-heading/.NET/Split-by-heading/README.md b/Word-document/Split-by-heading/.NET/Split-by-heading/README.md new file mode 100644 index 00000000..fb6df2f1 --- /dev/null +++ b/Word-document/Split-by-heading/.NET/Split-by-heading/README.md @@ -0,0 +1,129 @@ +# Split Word document by Headings using C# + +The Syncfusion [. NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **split a Word document by headings** using C#. + +## Steps to split Word document by headings programmatically + +Step 1: Create a new . NET Core console application project. + +Step 2: Install the [Syncfusion. DocIO. Net. Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to split Word document by headings. + +```csharp +using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read)) +{ + //Load the template document as stream + using (WordDocument document = new WordDocument(inputStream, FormatType.Docx)) + { + WordDocument newDocument = null; + WSection newSection = null; + int headingIndex = 0; + //Iterate each section in the Word document. + foreach (WSection section in document.Sections) + { + // Clone the section and add into new document. + if (newDocument != null) + newSection = AddSection(newDocument, section); + //Iterate each child entity in the Word document. + foreach (TextBodyItem item in section.Body.ChildEntities) + { + //If item is paragraph, then check for heading style and split. + //else, add the item into new document. + if (item is WParagraph) + { + WParagraph paragraph = item as WParagraph; + //If paragraph has Heading 1 style, then save the traversed content as separate document. + //And create new document for new heading content. + if (paragraph.StyleName == "Heading 1") + { + if (newDocument != null) + { + //Saves the Word document + string fileName = Path.GetFullPath(@"Output/Document") + (headingIndex + 1) + ".docx"; + SaveWordDocument(newDocument, fileName); + headingIndex++; + } + //Create new document for new heading content. + newDocument = new WordDocument(); + newSection = AddSection(newDocument, section); + AddEntity(newSection, paragraph); + } + else if (newDocument != null) + AddEntity(newSection, paragraph); + } + else + AddEntity(newSection, item); + } + } + //Save the remaining content as separate document. + if (newDocument != null) + { + //Saves the Word document + string fileName = Path.GetFullPath(@"Output/Document") + (headingIndex + 1) + ".docx"; + SaveWordDocument(newDocument, fileName); + } + } +} +``` + +Step 5: Add the helper methods to split a Word document. + +```csharp +/// +/// Add new section into Word document +/// +private static WSection AddSection(WordDocument newDocument, WSection section) +{ + //Create new session based on original document + WSection newSection = section.Clone(); + newSection.Body.ChildEntities.Clear(); + //Remove the first page header. + newSection.HeadersFooters.FirstPageHeader.ChildEntities.Clear(); + //Remove the first page footer. + newSection.HeadersFooters.FirstPageFooter.ChildEntities.Clear(); + //Remove the odd footer. + newSection.HeadersFooters.OddFooter.ChildEntities.Clear(); + //Remove the odd header. + newSection.HeadersFooters.OddHeader.ChildEntities.Clear(); + //Remove the even header. + newSection.HeadersFooters.EvenHeader.ChildEntities.Clear(); + //Remove the even footer. + newSection.HeadersFooters.EvenFooter.ChildEntities.Clear(); + //Add cloned section into new document + newDocument.Sections.Add(newSection); + return newSection; +} +/// +/// Add Entity in to new section +/// +private static void AddEntity(WSection newSection, Entity entity) +{ + //Add cloned item into the newly created section + newSection.Body.ChildEntities.Add(entity.Clone()); +} +/// +/// Save Word document +/// +private static void SaveWordDocument(WordDocument newDocument, string fileName) +{ + using (FileStream outputStream = new FileStream(Path.GetFullPath(fileName), FileMode.OpenOrCreate, FileAccess.ReadWrite)) + { + //Save file stream as Word document + newDocument.Save(outputStream, FormatType.Docx); + //Closes the document + newDocument.Close(); + newDocument = null; + } +} +``` + +More information about splitting a Word document can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/word-document/split-word-documents) section. diff --git a/Word-document/Split-by-placeholder-text/.NET/Split-by-placeholder-text/README.md b/Word-document/Split-by-placeholder-text/.NET/Split-by-placeholder-text/README.md new file mode 100644 index 00000000..f5ae44af --- /dev/null +++ b/Word-document/Split-by-placeholder-text/.NET/Split-by-placeholder-text/README.md @@ -0,0 +1,99 @@ +# Split Word document by PlaceHolder using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) allows you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **split a Word document by placeholders** using C#. + +## Steps to split Word document by placeholders programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; +using System.Collections.Generic; +using System.Text.RegularExpressions; +``` + +Step 4: Add the following code snippet in Program.cs file to split Word document by placeholders. + +```csharp +//Load an existing Word document into DocIO instance. +FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)) +{ + //Finds all the placeholder text in the Word document. + TextSelection[] textSelections = document.FindAll(new Regex("<<(.*)>>")); + if (textSelections != null) + { + #region Insert bookmarks at placeholders + //Unique ID for each bookmark. + int bkmkId = 1; + //Collection to hold the inserted bookmarks. + List bookmarks = new List(); + //Iterate each text selection. + for (int i = 0; i < textSelections.Length; i++) + { + #region Insert bookmark start before the placeholder + //Get the placeholder as WTextRange. + WTextRange textRange = textSelections[i].GetAsOneRange(); + //Get the index of the placeholder text. + WParagraph startParagraph = textRange.OwnerParagraph; + int index = startParagraph.ChildEntities.IndexOf(textRange); + string bookmarkName = "Bookmark_" + bkmkId; + //Add new bookmark to bookmarks collection. + bookmarks.Add(bookmarkName); + //Create bookmark start. + BookmarkStart bkmkStart = new BookmarkStart(document, bookmarkName); + //Insert the bookmark start before the start placeholder. + startParagraph.ChildEntities.Insert(index, bkmkStart); + //Remove the placeholder text. + textRange.Text = string.Empty; + #endregion + + #region Insert bookmark end after the placeholder + i++; + //Get the placeholder as WTextRange. + textRange = textSelections[i].GetAsOneRange(); + //Get the index of the placeholder text. + WParagraph endParagraph = textRange.OwnerParagraph; + index = endParagraph.ChildEntities.IndexOf(textRange); + //Create bookmark end. + BookmarkEnd bkmkEnd = new BookmarkEnd(document, bookmarkName); + //Insert the bookmark end after the end placeholder. + endParagraph.ChildEntities.Insert(index + 1, bkmkEnd); + bkmkId++; + //Remove the placeholder text. + textRange.Text = string.Empty; + #endregion + } + #endregion + #region Split bookmark content into separate documents + BookmarksNavigator bookmarksNavigator = new BookmarksNavigator(document); + int fileIndex = 1; + foreach (string bookmark in bookmarks) + { + //Move the virtual cursor to the location before the end of the bookmark. + bookmarksNavigator.MoveToBookmark(bookmark); + //Get the bookmark content as WordDocumentPart. + WordDocumentPart wordDocumentPart = bookmarksNavigator.GetContent(); + //Save the WordDocumentPart as separate Word document. + using (WordDocument newDocument = wordDocumentPart.GetAsWordDocument()) + { + //Save the Word document to file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Placeholder_" + fileIndex + ".docx"), FileMode.Create, FileAccess.ReadWrite)) + { + newDocument.Save(outputFileStream, FormatType.Docx); + } + } + fileIndex++; + } + #endregion + } +} +``` + +More information about the mail merge can be found in this [documentation](https://help.syncfusion.com/file-formats/docio/working-with-mailmerge) section. \ No newline at end of file diff --git a/Word-document/Split-by-section/.NET/Split-by-section/README.md b/Word-document/Split-by-section/.NET/Split-by-section/README.md new file mode 100644 index 00000000..b96f75cb --- /dev/null +++ b/Word-document/Split-by-section/.NET/Split-by-section/README.md @@ -0,0 +1,48 @@ +# Split Word document by Section using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **split a Word document by sections** using C#. + +## Steps to split Word document by sections programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to split Word document by sections. + +```csharp +using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +{ + //Load the template document as stream + using (WordDocument document = new WordDocument(inputStream, FormatType.Docx)) + { + int fileId = 1; + //Iterate each section from Word document + foreach (WSection section in document.Sections) + { + //Create new Word document + using (WordDocument newDocument = new WordDocument()) + { + //Add cloned section into new Word document + newDocument.Sections.Add(section.Clone()); + //Saves the Word document to MemoryStream + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Section") + fileId + ".docx", FileMode.OpenOrCreate, FileAccess.ReadWrite)) + { + newDocument.Save(outputStream, FormatType.Docx); + } + } + fileId++; + } + } +} +``` + +More information about splitting a Word document can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/word-document/split-word-documents) section. \ No newline at end of file diff --git a/Word-to-Image-conversion/First-page-of-Word-to-image/.NET/First-page-of-Word-to-image/README.md b/Word-to-Image-conversion/First-page-of-Word-to-image/.NET/First-page-of-Word-to-image/README.md new file mode 100644 index 00000000..a1a4a184 --- /dev/null +++ b/Word-to-Image-conversion/First-page-of-Word-to-image/.NET/First-page-of-Word-to-image/README.md @@ -0,0 +1,46 @@ +# Convert Word document to Image using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, edit, and convert Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **convert a Word document to Image** using C#. + +## Steps to convert Word to Image programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIORenderer.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIORenderer.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIORenderer; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to convert a Word document to image. + +```csharp +using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open)) +{ + //Loads an existing Word document. + using (WordDocument wordDocument = new WordDocument(fileStream, FormatType.Automatic)) + { + //Creates an instance of DocIORenderer. + using (DocIORenderer renderer = new DocIORenderer()) + { + //Convert the first page of the Word document into an image. + Stream imageStream = wordDocument.RenderAsImages(0, ExportImageFormat.Jpeg); + //Resets the stream position. + imageStream.Position = 0; + //Creates the output image file stream. + using (FileStream fileStreamOutput = File.Create(Path.GetFullPath(@"Output/Output.jpeg"))) + { + //Copies the converted image stream into created output stream. + imageStream.CopyTo(fileStreamOutput); + } + } + } +} +``` + +More information about Word to Image conversion can be found in this [documentation](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/word-to-image) section. \ No newline at end of file diff --git a/Word-to-Markdown-conversion/Convert-Word-to-Markdown/.NET/Convert-Word-to-Markdown/README.md b/Word-to-Markdown-conversion/Convert-Word-to-Markdown/.NET/Convert-Word-to-Markdown/README.md new file mode 100644 index 00000000..630508ca --- /dev/null +++ b/Word-to-Markdown-conversion/Convert-Word-to-Markdown/.NET/Convert-Word-to-Markdown/README.md @@ -0,0 +1,38 @@ +# Convert Word document to Markdown using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, edit, and convert Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **convert a Word document to Markdown** using C#. + +## Steps to convert Word to Markdown programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to convert a Word document to Markdown. + +```csharp +//Open a file as a stream. +using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +{ + //Load the file stream into a Word document. + using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)) + { + //Create a file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.md"), FileMode.Create, FileAccess.ReadWrite)) + { + //Save a Markdown file to the file stream. + document.Save(outputFileStream, FormatType.Markdown); + } + } +} +``` + +More information about Word to Markdown conversion can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/convert-word-document-to-markdown-in-csharp) section. \ No newline at end of file diff --git a/Word-to-PDF-Conversion/Convert-Word-document-to-PDF/.NET/Convert-Word-document-to-PDF/README.md b/Word-to-PDF-Conversion/Convert-Word-document-to-PDF/.NET/Convert-Word-document-to-PDF/README.md new file mode 100644 index 00000000..071a7c29 --- /dev/null +++ b/Word-to-PDF-Conversion/Convert-Word-document-to-PDF/.NET/Convert-Word-document-to-PDF/README.md @@ -0,0 +1,49 @@ +# Convert Word document to PDF using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, edit, and convert Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **convert a Word document to PDF** using C#. + +## Steps to convert Word to PDF programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIORenderer.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIORenderer.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIORenderer; +using Syncfusion.OfficeChart; +using Syncfusion.Pdf; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to convert a Word document to PDF. + +```csharp +using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open)) +{ + //Loads an existing Word document. + using (WordDocument wordDocument = new WordDocument(fileStream, Syncfusion.DocIO.FormatType.Automatic)) + { + //Creates an instance of DocIORenderer. + using (DocIORenderer renderer = new DocIORenderer()) + { + //Sets Chart rendering Options. + renderer.Settings.ChartRenderingOptions.ImageFormat = ExportImageFormat.Jpeg; + //Converts Word document into PDF document. + using (PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument)) + { + //Saves the PDF file to file system. + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) + { + pdfDocument.Save(outputStream); + } + } + } + } +} +``` + +More information about Word to PDF conversion can be found in this [documentation](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/word-to-pdf) section. \ No newline at end of file diff --git a/Word-to-PDF-Conversion/Convert-Word-into-accessible-PDF/.NET/Convert-Word-into-accessible-PDF/README.md b/Word-to-PDF-Conversion/Convert-Word-into-accessible-PDF/.NET/Convert-Word-into-accessible-PDF/README.md new file mode 100644 index 00000000..c724db80 --- /dev/null +++ b/Word-to-PDF-Conversion/Convert-Word-into-accessible-PDF/.NET/Convert-Word-into-accessible-PDF/README.md @@ -0,0 +1,48 @@ +# Convert Word document to PDF/UA using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, edit, and convert Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **convert a Word document to PDF/UA** using C#. + +## Steps to convert Word to PDF/UA programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIORenderer.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIORenderer.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIORenderer; +using Syncfusion.Pdf; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to convert a Word document to PDF/UA. + +```csharp +using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open)) +{ + //Loads an existing Word document. + using (WordDocument wordDocument = new WordDocument(fileStream, Syncfusion.DocIO.FormatType.Automatic)) + { + //Creates an instance of DocIORenderer. + using (DocIORenderer renderer = new DocIORenderer()) + { + //Sets true to preserve document structured tags in the converted PDF document. + renderer.Settings.AutoTag = true; + //Converts Word document into PDF document. + using (PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument)) + { + //Saves the PDF file to file system. + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) + { + pdfDocument.Save(outputStream); + } + } + } + } +} +``` + +More information about Word to PDF/UA can be found in this [documentation](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/word-to-pdf#accessible-pdf-document) section. \ No newline at end of file diff --git a/Word-to-PDF-Conversion/PDF-conformance-level/.NET/PDF-conformance-level/README.md b/Word-to-PDF-Conversion/PDF-conformance-level/.NET/PDF-conformance-level/README.md new file mode 100644 index 00000000..b30b83ec --- /dev/null +++ b/Word-to-PDF-Conversion/PDF-conformance-level/.NET/PDF-conformance-level/README.md @@ -0,0 +1,48 @@ +# Convert Word document to PDF/A using C# + +The Syncfusion [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) enables you to create, read, edit, and convert Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **convert a Word document to PDF/A** using C#. + +## Steps to convert Word to PDF/A programmatically + +Step 1: Create a new .NET Core console application project. + +Step 2: Install the [Syncfusion.DocIORenderer.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIORenderer.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). + +Step 3: Include the following namespaces in the Program.cs file. + +```csharp +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIORenderer; +using Syncfusion.Pdf; +using System.IO; +``` + +Step 4: Add the following code snippet in Program.cs file to convert a Word document to PDF/A. + +```csharp +using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open)) +{ + //Loads an existing Word document. + using (WordDocument wordDocument = new WordDocument(fileStream, Syncfusion.DocIO.FormatType.Automatic)) + { + //Creates an instance of DocIORenderer. + using (DocIORenderer renderer = new DocIORenderer()) + { + //Set the conformance for PDF/A-1b conversion. + renderer.Settings.PdfConformanceLevel = PdfConformanceLevel.Pdf_A1B; + //Converts Word document into PDF document. + using (PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument)) + { + //Saves the PDF file to file system. + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) + { + pdfDocument.Save(outputStream); + } + } + } + } +} +``` + +More information about converting Word document to PDF with conformance can be found in this [documentation](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/word-to-pdf#pdf-conformance-level) section. \ No newline at end of file