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.NETsolution (MuPDF.NET.sln).Set the following in Visual Studio:
Release,x64andBuildThe result is
MuPDF.NET.dllandDemo.exe. Users can useMuPDF.NET.dllas a reference inC#project and use defined classes and functions.Demo.exeis 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.
License and Copyright#
MuPDF.NET is available under the Artifex Community License and commercial license agreements. If you determine you cannot meet the requirements of the Artifex Community License, please contact Artifex for more information regarding a commercial license.
