In this blog, we are going to see how easy it is to review a Word document using Syncfusion’s Word framework. Comments and track changes are features provided in Microsoft Word for reviewing. In a similar way, our Word framework includes support to track changes, accept or reject the tracked changes, and insert, reply, resolve, and delete comments. The most interesting thing is it works without Microsoft Word or Office interop dependencies.
Syncfusion Word Processor (also known as Document Editor) is a user interface web component that allows you to compose, edit, view, and print Word documents interactively in a web application. It provides all the standard word processing features such as formatting contents, resizing images and tables, finding and replacing text, generating tables of content, and so on. This component is available in JavaScript (ES5 and ES6), Angular, React, Vue, ASP.NET MVC, ASP.NET Core, and Blazor platforms.
Note: The Word Processor (Document Editor) component requires server-side interaction for the following operations: · Open Word documents (converting Word documents to SFDT file format). · Paste content with formatting. · Restrict editing. · Spell checking. Syncfusion provides a server-side library for the following platforms: · ASP.NET Core · ASP.NET MVC · Java You can find the web API projects for the supported platforms in this GitHub repository. |
Comments
Comments are notes, questions, and suggestions that a reviewer or reader offers to other people working on a Word document. The Syncfusion Word Processor component allows you to do the following actions with comments:
- Insert a new comment for the selected content.
- Edit an existing comment.
- Reply to a comment.
- Mark a comment as resolved once the suggested action or change is done.
- Delete a single comment or all comments.
Since the Document Editor component is modularized, not all the features are enabled by default. To enable the commenting ability, set the enableComment property as true. By default, the enableComment property is set to false , so commenting is disabled in the DocumentEditor component.
Note: The commenting feature will be enabled by default when using the DocumentEditorContainer component.
To insert a new comment, select the text that you want to comment on. Then, click either the Comments option in the toolbar or the New comment option in the review tab, as shown in the image below. The editor will set the author for the new comment based on the value of the currentUser property.
In the new comment box of the review tab, add the necessary content and click the post icon. If you want to discard the comment, then click the cancel icon.
To edit an existing comment, click the options button in the comment and then click Edit. Now you can edit the comment text.
Similarly, you can delete, reply to, and resolve a comment using the other options. The re-open option will be displayed only for a resolved comment.
Track changes
The track changes feature tracks all the insertions and deletions made to the Word document. You can see what was inserted or deleted in a specific document by whom and when. Also, it allows you to accept or reject the changes made to the document.
Syncfusion greatly facilitates the developer community with feature-rich Word processing components that allow developers to add advanced Word document reviewing capabilities within their applications. The products are:
- An advanced Word Processor (editor) for tracking changes in a Word document that provides an intuitive user interface in web applications.
- A comprehensive Word Library that allows users to access and accept or reject the tracked changes in a Word document using powerful APIs in .NET and Java.
Intuitive user interface for tracking changes
When the track changes option is enabled in the Word Processor, the edits or changes made are marked with:
- A strikethrough for deleted information.
- An underline for inserted information.
The Word Processor provides an intuitive user interface to do the following actions with the track changes feature:
- Enable or disable track changes feature.
- Access all the tracked revisions.
- Accept or reject a specific change.
- Accept or reject all changes.
- Filter changes based on users.
- Navigate between changes.
To enable or disable track changes in the Document Editor, toggle the Track Changes option in the toolbar.
Accept or reject changes
Syncfusion provides a comprehensive Word Library in both .NET (C#, VB.NET) and Java, giving you complete freedom in choosing the best fit for server-side automation code for your projects. It provides powerful APIs to access revisions (tracked changes) and accept or reject a change or group of changes.
You can automate accepting or rejecting tracked changes on the server side using the Syncfusion Word Library before displaying the Word document in the web browser. Before accepting or rejecting the changes, you can validate and filter the changes based on:
- Authors
- Revision types (insertion, deletion, formatting, move from, move to, style definition change).
The following images show the tracked changes in a Word document.
Accept the changes
The following C# code example illustrates how to accept all the changes made by an author in a Word document using the Word Library.
//Reads the input Word document.
Stream inputStream = File.OpenRead(Path.GetFullPath(@"../../../../../../Data/InputWithTrackedChanges.docx"));
string authorName = "Steven Buchanan";
int acceptedChangesCount = AcceptChanges(inputStream, authorName);
Console.WriteLine("Accepted {0} changes made by {1}.", acceptedChangesCount, authorName);
static int AcceptChanges(Stream inputStream, string authorName)
{
int acceptedChangesCount = 0;
//Creates new Word document instance for Word processing.
using (WordDocument document = new WordDocument())
{
//Opens the Word document containing tracked changes.
document.Open(inputStream, FormatType.Docx);
inputStream.Dispose();
//Iterates all the revisions present in the Word document.
for (int i = document.Revisions.Count - 1; i >= 0; i--)
{
//Validates the author of current revision to accept/reject it.
if (document.Revisions[i].Author == authorName)
{
//Accepts the current revision.
document.Revisions[i].Accept();
acceptedChangesCount++;
}
//Resets i to last item, since accepting one revision will impact all its related revisions and leads to change in Revsions
if (i > document.Revisions.Count - 1)
i = document.Revisions.Count;
}
//Saves the Word document as DOCX format
using (Stream docStream = File.Create(Path.GetFullPath(@"../../../OutputAfterAcceptingChanges.docx")))
{
document.Save(docStream, FormatType.Docx);
}
}
return acceptedChangesCount;
}
For more information, refer to the accept all changes made by an user project sample.
The resultant Word document looks as follows.
Similarly, you can filter all the changes made by an author and reject the filtered changes.
Reject the changes
The following C# code example illustrates how to reject the insert and delete revisions made by all authors and keep the formatting changes in a Word document using the Word Library.
//Reads the input Word document.
Stream inputStream = File.OpenRead(Path.GetFullPath(@"../../../../../../Data/InputWithTrackedChanges.docx"));
RevisionType revisionType = RevisionType.Insertions | RevisionType.Deletions;
int rejectedChangesCount = RejectChanges(inputStream, revisionType);
static int RejectChanges(Stream inputStream, RevisionType revisionType)
{
int rejectedChangesCount = 0;
//Creates new Word document instance for Word processing.
using (WordDocument document = new WordDocument())
{
//Opens the Word document containing tracked changes.
document.Open(inputStream, FormatType.Docx);
inputStream.Dispose();
//Iterates all the revisions present in the Word document.
for (int i = document.Revisions.Count - 1; i >= 0; i--)
{
//Validates the revision type of current revision to accept/reject it.
if ((document.Revisions[i].RevisionType & revisionType) != 0)
{
//Rejects the current revision.
document.Revisions[i].Reject();
rejectedChangesCount++;
}
//Resets i to last item, since rejecting one revision will impact all its related revisions. and lead to change in Revsions.
if (i > document.Revisions.Count - 1)
i = document.Revisions.Count;
}
//Saves the Word document as DOCX format.
using (Stream docStream = File.Create(Path.GetFullPath(@"../../../OutputAfterRejectingChanges.docx")))
{
document.Save(docStream, FormatType.Docx);
}
}
return rejectedChangesCount;
}
For more information, refer to the reject all the changes made by a user project.
The resultant Word document looks as follows.
Similarly, you can filter the insert and delete revisions made by an author or all authors and accept the filtered changes in a Word document. You can get more information on this from the documentation.
GitHub repository
For more information, refer to the complete, working example of reviewing a Word document.
Conclusion
With the help of the comments and track changes functionalities, you can provide reviewing capability for a Word document in your web application with ease.
Take a moment to peruse the documentation, where you’ll find other options and features, all with accompanying code examples. If you are new to our Word Processor (Document Editor), it is highly recommended that you follow our Getting Started guide.
Are you already a Syncfusion user? You can download the product setup here. If you’re not yet a Syncfusion user, you can download a free, 30-day trial here.
If you have any questions about these features, please let us know in the comments below. You can also contact us through our support forum, support portal, or feedback portal. We are happy to assist you!
Top comments (0)