If you are working with Word documents in code in .NET Standard 2.0 targeted applications, there will be times when you do not want to store your data in a Word format. A PDF (Portable Document Format) is an ideal format for a variety of reasons.

Why convert a Word document to PDF?

  • You do not have Microsoft Office installed on your system, but still want to print or distribute your Word documents.
  • You want the format of your documents to be consistent. A PDF will keep all original formatting, regardless of the operating system or computer used to open the file.
  • You need long-term data preservation. Working with PDF formats will allow you to share, collaborate, and ensure the security of the content within your documents, long-term.
  • You may have designed Word documents from other data sources and need to create documents such as:

    • Invoice slips
    • Newsletters
    • Journals
    • Project Plans
    • Articles

GrapeCity Documents for Word (GcWord) is a Word API that offers a complete solution to program and work with Word documents, with zero dependancies on Microsoft Office.

With GcWord, developers can create powerful document conversions for archival and delivery systems in .NET Standard 2.0 targeted applications. You can convert Word documents to PDF on all three operating systems -- Windows, Mac, and Linux.

GcWord's feature-rich object model is based on Microsoft Office API, Word Javascript API, and OpenXML SDK. The architecture is simple and handy to use. Developers can make use of its object model to create DOCX files through code, load DOCX file, and access the object model. You can add, remove, and modify objects (and their properties like formatting), save the file to a DOCX file or export it to PDF. You can do all this in any .NET Standard 2.0 targeted application.

In this demo, we'll cover:

  • How to load the Word document (.docx) file in GcWord
  • Export the Word document to PDF

Step 1: Exporting Word documents to PDF

Learn how to install GcWord in a .NET Core console application and create a Word document in code, using GcWord.

At the end of this blog, your Word document would look like this:

Exporting Word documents to PDF

Step 2: Add namespace

In order to export a Word document to PDF, you need to download and install GrapeCity.Documents.Layout Nuget Package.

Follow these steps:

Visual Studio for Windows

  1. Right-click the project in Solution Explorer and choose Manage NuGet Packages.
  2. In Package source in the top right, select nuget.org.
  3. Click Browse tab in top left and enter "GrapeCity.Documents" as the search string. You should see several GrapeCity.Documents packages listed.
  4. Select GrapeCity.Documents.Layout, and click Install. Accept the license agreement.

Visual Studio for MAC

  1. In the Package source on the top left, choose nuget.org.
  2. Click Browse tab on the top right and search for "Grapecity.Documents."
  3. On the left panel, choose GrapeCity.Documents.Layout.
  4. On the right panel, click Install.
  5. Choose 'I Accept' in the next screen.

Visual Studio Code for Linux

  1. From Extensions, install the Nuget Package Manager and activate it.
  2. In Visual Studio Code, press Ctrl+P to open the file command box, type > in it, find "Nuget Package Manager: Add Package" in the list that opens, and click it.
  3. In the search box that opens, type "GrapeCity" and press Enter. This should bring up the list of available GrapeCity packages, GrapeCity.Documents.Layout among them.
  4. Select it and then the build number. The package will be added to the application.

Step 3: Load a Word document (.docx) file in GcWord

Add following lines of code in main function of Program.cs. This code will create a GcWord document object. Then load the Word document into it.

var doc = new GcWordDocument();
var path = Path.Combine(@"ImportanceOfWetlands.docx");

Step 4: Export the Word document to PDF

Instead of saving to Word, you can directly save the Word document to PDF using following code:


Run the application. Your PDF would look like this:

Export the Word document to PDF

Watch the video tutorial

It's that simple! We hope you like this feature. Do you have a question or comment? Please leave it in the thread below.

View more demos and features of GcWord.

Export your Word document to a PDf in .NET Apps

Download GrapeCity Documents for Word

Download Now!