Skip to main content
A newer version of this page is available. .

Use Office File API on macOS (.NET Core)

  • 2 minutes to read

This tutorial describes how to create a simple Office File API application for .NET Core on macOS.

Prerequisites

  1. .NET Core SDK 2.1 or later.

  2. A code editor. This tutorial uses Visual Studio Code.

  3. Libgdiplus library. This library is required to use the System.Drawing functionality in Office File API applications.

    Add the Homebrew package manager to your system and use the following terminal command to install the latest libgdiplus version and the library dependencies:

    brew install freetype harfbuzz fontconfig icu4c mono-libgdiplus

Create the Application

  1. Create a folder for you project (OfficeConsoleApp in this example) and open it in Visual Studio Code.

  2. Click View -> Terminal in Visual Studio Code’s main menu to open the integrated terminal.

  3. Use the dotnet new command to create a new console application.

    dotnet new console
    

    This command adds the following files to your folder:

    • OfficeConsoleApp.csproj / OfficeConsoleApp.vbproj

    • Program.cs / Program.vb.

  4. Obtain your NuGet feed URL and install the DevExpress.Document.Processor NuGet package.

    Important

    You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this package in production code.

    # The -s key specifies the package source (DevExpress NuGet feed)
    dotnet add package DevExpress.Document.Processor -v 20.2.13 -s https://nuget.devexpress.com/{your-feed-authorization-key}/api
    
  5. Paste the code below in the Main method of the Program.cs file (or Program.vb file’s Main procedure for Visual Basic). This example shows how to convert a DOCX file to PDF.

    using DevExpress.XtraRichEdit;
    // ...
    
    static void Main(string[] args)
    {
        using (RichEditDocumentServer documentProcessor =
            new RichEditDocumentServer())
        {
            // Load a document from a file.
            documentProcessor.LoadDocument("Document.docx", DocumentFormat.OpenXml);
            // Export the document to PDF.
            documentProcessor.ExportToPdf("PdfDocument.pdf");
        }
    }
    

Run the Application

Type dotnet run in the terminal window to run the program.

dotnet run

The image below shows the result.

Office_Getting_Started_On-macOS_Result