Create PDF files on Linux or macOS in C# using the .NET Core application

The following example shows how to create a PDF document using the GemBox.Pdf library on Linux (Ubuntu).

A generated PDF document from .NET Core application running on Linux (Ubuntu)
A screenshot of a PDF file created with .NET Core on Linux

Prerequisites

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

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, GemBoxExample.

Selecting the folder in Visual Studio Code you want your console project to be in
A screenshot of the 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 the 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 in Visual Studio Code
A screenshot of the Visual Studio Code new console command

3. Edit project files

  • Add a reference to GemBox.Pdf in the GemBoxExample.csproj file:
<ItemGroup>
<PackageReference Include="GemBox.Pdf" Version="*" />
</ItemGroup>
  • Edit the C# code in Program.cs file:
using GemBox.Pdf;

class Program
{
static void Main()
{
// If using the Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");

using (var document = new PdfDocument())
{
// Add a first empty page.
document.Pages.Add();

// Add a second empty page.
document.Pages.Add();

document.Save("Output.pdf");
}
}
}

4. Run the console project

  • In the terminal window execute the following command: dotnet run

  • This command will run your Console application and create a PDF document (Output.pdf) that you can open in any PDF application.

Running a C# console project in Visual Studio Code
A screenshot of the Visual Studio Code run command

Limitations on Linux or macOS

You can use the full functionality of GemBox.Pdf on Unix systems, but with the following exceptions:

These features currently have WPF dependencies which means they require a .NET Windows Desktop Runtime. However, we have plans to provide cross-platform support for them in future releases.

Next steps

GemBox.Pdf is a .NET library that enables developers to read, merge and split PDF files or execute low-level object manipulations from .NET applications in a simple and efficient way.