Create Word (DOCX) or PDF file on Linux or macOS

GemBox.Document provides support for .NET Standard 2.0, a cross-platform specification of .NET APIs, which is why it can be used on non-Windows platforms like Linux and macOS.

The following example shows how you can create a Word document and a PDF file using GemBox.Document on Linux (Ubuntu).

Generated Word document from .NET Core application running on Linux (Ubuntu)
Screenshot of Word file created with .NET Core on Linux

Prerequisites

After installing the requirements listed above you can follow these steps that show how you can easily use a Visual Studio Code (VS Code) to create a simple Console project and a C# code that generates DOCX and PDF files.

1. Open a project folder

  • Open VS Code.
  • Click "Open Folder" on the EXPLORER panel.
  • Select the folder you want your console project to be in, for instance a folder named GemBoxExample.
Selecting the folder you want your console project to be in
Screenshot of Visual Studio Code folder selection

2. Create a new console project

  • Open Integrated Terminal in VS Code by clicking "View" > "Terminal" or using CTRL + ` shortcut.
  • In the terminal window execute following command: dotnet new console
  • This command will create a code file (Program.cs) and a project file (GemBoxExample.csproj) inside the opened folder.
Creating a C# console project
Screenshot of Visual Studio Code new console command

3. Edit project files

  • Add a reference to GemBox.Document and its dependencies in GemBoxExample.csproj file:
    <ItemGroup>
      <PackageReference Include="GemBox.Document" Version="*" />
      
      <!-- Required if document has any image. -->
      <PackageReference Include="System.Drawing.Common" Version="*" />
      
      <!-- Required if PDF file is digitally signed. -->
      <PackageReference Include="System.Security.Cryptography.Pkcs" Version="*" />
    </ItemGroup>
    Note that System.Drawing.Common assembly has a reference to a native libgdiplus library which must be installed on a non-Windows system.
    To install it on Linux use the following command: sudo apt-get install libgdiplus
    To install it on macOS use Homebrew with the following command: brew install mono-libgdiplus
  • Edit C# code in Program.cs file:
    using GemBox.Document;
    
    class Program
    {
        static void Main()
        {
            // If using Professional version, put your serial key below.
            ComponentInfo.SetLicense("FREE-LIMITED-KEY");
    
            DocumentModel document = new DocumentModel();
    
            Section section = new Section(document);
            document.Sections.Add(section);
    
            Paragraph paragraph = new Paragraph(document);
            section.Blocks.Add(paragraph);
    
            Run run = new Run(document, "Hello World!");
            paragraph.Inlines.Add(run);
    
            document.Save("Output.docx");
            document.Save("Output.pdf");
        }
    }

4. Run the console project

  • In the terminal window execute following command: dotnet run
  • This command will run your Console application and create a Word document (Output.docx) and a PDF file (Output.pdf) that you can open in any Word and PDF applications.
Running a C# console project
Screenshot of Visual Studio Code run command

Limitations on Linux or macOS

The .NET Standard version of GemBox.Document has full functionality of .NET Framework version, but with few rendering limitations (unsupported features):

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Document yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.