Articles in this section
Category / Section

How to preserve simple markup, all markup, and no markup of track changes during Word to PDF conversion

6 mins read

Syncfusion® .NET Word Library (DocIO) used to create, read, edit and convert Word documents programmatically without Microsoft Word or Interop dependencies. Using this library, you can** preserve simple markup, all markup, and no markup of track changes during Word to PDF conversion in C#**.

Steps to preserve simple markup, all markup, and no markup of track changes in Word to PDF :

  1. Create a new ASP.NET Core Web application (Model-View-Controller) project.
    ASP.NET Core Web application (Model-View-Controller) application in Visual Studio.
  2. Install the Syncfusion.DocIORenderer.Net.Core NuGet package as a reference to your project from NuGet.org.
    Add Syncfusion.DocIORenderer.Net.Core NuGet package

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion® license key in your application to use the components without trail message.

  1. Include the following namespaces in the HomeController.cs file.

C#:

using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIORenderer;
using Syncfusion.Pdf;
  1. A default action method named Index will be present in HomeController.cs. Right click on Index method and select Go To View where you will be directed to its associated view page Index.cshtml.
  2. Add a new button and drop down options in the Index.cshtml as shown below.

C#:

@{
   Html.BeginForm("ConvertWordtoPDF", "Home", FormMethod.Get);
   {
       <div class="Common">
           <div class="tablediv">
               <div class="rowdiv">
                   This sample illustrates how to show track changes mark up in Word to PDF conversion using Essential DocIO.
               </div>
                
               <div class="rowdiv" style="border-width: 0.5px;border-style:solid; border-color: lightgray; padding: 1px 5px 7px 5px">
                   <div class="rowdiv" style="margin-top: 8px">
                       <input type="submit" value="Convert Word to PDF" name="button" style="width:200px;height:27px" />
                       <br />
                   </div>
                   <div>
                       Select Track changes option:
                       <select id="TrackChangesOptions" name="TrackChangesOptions">
                           <option value="0">Simple Markup</option>
                           <option value="1">All Markup</option>
                           <option value="2">No Markup</option>
                       </select>

                   </div>
               </div>
           </div>
           <br />
       </div>
   }
   Html.EndForm();
}
  1. Add a new action method ConvertWordtoPDF in HomeController.cs and include the below code snippet to preserve simple markup, all markup, and no markup of track changes during Word to PDF conversion.

C#:

//Open the file as Stream.
using (FileStream docStream = new FileStream(Path.GetFullPath("Data/Template.docx"), FileMode.Open, FileAccess.Read))
{
   //Loads file stream into Word document.
   using (WordDocument wordDocument = new WordDocument(docStream, FormatType.Automatic))
   {
       #region Track changes option
       //Sets revision types to preserve simple markup track changes in Word to PDF conversion.
       if (TrackChangesOptions == "0")
       {
           wordDocument.RevisionOptions.ShowMarkup = RevisionType.Deletions | RevisionType.Formatting | RevisionType.Insertions | RevisionType.MoveFrom | RevisionType.MoveTo | RevisionType.StyleDefinitionChange;
           wordDocument.RevisionOptions.ShowInBalloons = RevisionType.None;
       }
       //Sets revision types to preserve all markup track changes in Word to PDF conversion.
       else if (TrackChangesOptions == "1")
       {
           wordDocument.RevisionOptions.ShowMarkup = RevisionType.Deletions | RevisionType.Formatting | RevisionType.Insertions | RevisionType.MoveFrom | RevisionType.MoveTo | RevisionType.StyleDefinitionChange;
       }
       //Sets none revision type to preserve no markup track changes in Word to PDF conversion.
       else if (TrackChangesOptions == "2")
       {
           wordDocument.RevisionOptions.ShowMarkup = RevisionType.None;
       }
       #endregion
       //Instantiation of DocIORenderer for Word to PDF conversion.
       using (DocIORenderer render = new DocIORenderer())
       {
           //Converts Word document into PDF document.
           PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);

           //Saves the PDF document to MemoryStream.
           MemoryStream stream = new MemoryStream();
           pdfDocument.Save(stream);
           stream.Position = 0;

           //Download PDF document in the browser.
           return File(stream, "application/pdf", "Sample.pdf");
       }
   }
}

A complete working sample to preserve simple markup, all markup, and no markup of track changes during Word to PDF conversion in C# can be downloaded from GitHub.

By executing the program, you will get the PDF document as follows.

For Simple Markup option:

Output of simple markup in Word to PDF conversion in C#

For All Markup option:

Output of all markup in Word to PDF conversion in C#

For No Markup option:

Output of no markup in Word to PDF conversion in C#

Take a moment to peruse the documentation, where you can find basic Word document processing options along with the features like mail merge, merge, and compare documents, find and replace text in the Word document, protect the Word documents, and most importantly, the PDF and Image conversions with code examples.

Explore more about the rich set of Syncfusion® Word Framework features.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied