Getting Started#

Prerequisites#

  • Visual Studio 2019, 2022

  • .NET 8.0 or later

  • Windows OS / Linux

Usage with Nuget#

The steps to install and run MuPDF.NET in a standard .NET console environment from the command line are described below.

Install DotNet#

First, make sure you have the .NET SDK installed:

# Check if .NET is installed
dotnet --version

# If not installed, install it (Ubuntu/Debian example)
sudo apt update
sudo apt install dotnet-sdk-8.0

Or, if on Windows, go to the Official Installer from Microsoft.

Create a project#

Let’s create a simple example project called “MyProject” and run it:

# Create a new console app
dotnet new console -n MyProject

# Navigate to the project directory
cd MyProject

# Run the project
dotnet run

This starter project should just print "Hello, World!" once run.

Add the package#

Now add the MuPDF.NET package to your existing project by adding the MuPDF.NET package from NuGet:

dotnet add package MuPDF.NET

Use the package#

Let’s try creating a PDF and adding some text.

Open your project and edit the Program.cs file

Edit the Program.cs file#

Add the following code:

using MuPDF.NET;

Document doc = new Document();
Page page = doc.NewPage();
string text = "Made with MuPDF.NET"; // define some text!
MuPDF.NET.Font font = new MuPDF.NET.Font("helv"); // define a font to use, in this case Helvetica
MuPDF.NET.TextWriter tw = new MuPDF.NET.TextWriter(page.Rect); // define the rectangle for the text
tw.Append(new(50, 100), text, font); // define the point where you want to add the text
tw.WriteText(page); // use the TextWriter to write the text to the page
doc.Save("hello_world.pdf"); // save the result!

Save & Run#

Save the file and again run with:

dotnet run

You should now have a PDF file in the project folder ready to view - all created with MuPDF.NET!

Try more#

See further examples in The Basics for the typical kind of things you may want to do. If you get stuck, have new ideas, find something that you can’t do or have a feature request please visit the MuPDF Blog and let us know.

How to build#

  • Clone the GitHub project.

  • Open the MuPDF.NET solution (MuPDF.NET.sln).

  • Set the following in Visual Studio: Release, x64 and Build

  • The result is MuPDF.NET.dll and Demo.exe. Users can use MuPDF.NET.dll as a reference in C# project and use defined classes and functions. Demo.exe is one of examples.

Adobe PDF References#

Note

This PDF Reference manual published by Adobe is frequently quoted throughout this documentation. It can be viewed and downloaded from opensource.adobe.com.