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
.NET Core SDK 2.1 or later.
A code editor. This tutorial uses Visual Studio Code.
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
Create a folder for you project (OfficeConsoleApp in this example) and open it in Visual Studio Code.
Click View -> Terminal in Visual Studio Code’s main menu to open the integrated terminal.
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.
Obtain your NuGet feed URL and install the DevExpress.Document.Processor NuGet package.
# The -s key specifies the package source (DevExpress NuGet feed) dotnet add package DevExpress.Document.Processor -v 20.1.17 -s https://nuget.devexpress.com/{your-feed-authorization-key}/api
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.