Mavusi.PdfSharpCore 2.0.2

dotnet add package Mavusi.PdfSharpCore --version 2.0.2
                    
NuGet\Install-Package Mavusi.PdfSharpCore -Version 2.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mavusi.PdfSharpCore" Version="2.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mavusi.PdfSharpCore" Version="2.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Mavusi.PdfSharpCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Mavusi.PdfSharpCore --version 2.0.2
                    
#r "nuget: Mavusi.PdfSharpCore, 2.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Mavusi.PdfSharpCore@2.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Mavusi.PdfSharpCore&version=2.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Mavusi.PdfSharpCore&version=2.0.2
                    
Install as a Cake Tool

Mavusi.PdfSharpCore

NuGet Version CI codecov.io

A modern, lightweight PDF library for .NET 8, 9, and 10 with zero external dependencies for image processing.

Why Mavusi.PdfSharpCore?

This is a fork of PdfSharpCore with significant improvements focused on:

Key Features

No External Image Dependencies - Native support for JPEG, PNG, and BMP image formats without requiring ImageSharp or any other external libraries
Modern .NET Support - Multi-targeted for .NET 8, 9, and 10
Resilient PDF Reading - Added PdfReadAccuracy.Lazy mode for handling broken or non-standard PDFs
Digital Signature Support - Preliminary validation of PDF digital signatures via PdfDocument.IsSigned and PdfDocument.Signatures
Trim-Friendly - Optimized for .NET trimming to reduce deployment size

What's Different from the Original?

This fork removes heavy dependencies (ImageSharp, SharpZipLib) while adding native image processing capabilities and enhanced PDF reading modes. The result is a leaner, faster library with better compatibility.

Original PdfSharpCore by ststeiger: https://github.com/ststeiger/PdfSharpCore

Installation

Install via NuGet Package Manager:

dotnet add package Mavusi.PdfSharpCore

Or via Package Manager Console:

Install-Package Mavusi.PdfSharpCore

Quick Start Examples

Basic PDF Creation

Create a simple PDF document with text:

using PdfSharpCore.Drawing;
using PdfSharpCore.Pdf;

var document = new PdfDocument();
var page = document.AddPage();

var renderer = XGraphics.FromPdfPage(page);
var font = new XFont("Arial", 12);

renderer.DrawString(
    "Hello, World!",
    font,
    XBrushes.Black,
    new XPoint(12, 12)
);

document.Save("output.pdf");

Working with Multiple Pages

using PdfSharpCore.Drawing;
using PdfSharpCore.Pdf;

var document = new PdfDocument();

// Add first page
var page1 = document.AddPage();
var gfx1 = XGraphics.FromPdfPage(page1);
gfx1.DrawString("Page 1", new XFont("Arial", 20), XBrushes.Black, new XPoint(20, 20));

// Add second page
var page2 = document.AddPage();
var gfx2 = XGraphics.FromPdfPage(page2);
gfx2.DrawString("Page 2", new XFont("Arial", 20), XBrushes.Blue, new XPoint(20, 20));

document.Save("multipage.pdf");

Drawing Shapes and Graphics

using PdfSharpCore.Drawing;
using PdfSharpCore.Pdf;

var document = new PdfDocument();
var page = document.AddPage();
var gfx = XGraphics.FromPdfPage(page);

// Draw a rectangle
var pen = new XPen(XColors.Navy, 2);
gfx.DrawRectangle(pen, 50, 50, 200, 100);

// Draw a filled ellipse
var brush = new XSolidBrush(XColor.FromArgb(128, 0, 255, 0));
gfx.DrawEllipse(brush, 100, 200, 150, 100);

// Draw a line
gfx.DrawLine(XPens.Red, 0, 0, page.Width, page.Height);

document.Save("shapes.pdf");

Adding Images (No External Dependencies!)

using PdfSharpCore.Drawing;
using PdfSharpCore.Pdf;

var document = new PdfDocument();
var page = document.AddPage();
var gfx = XGraphics.FromPdfPage(page);

// Load and draw image - supports JPEG, PNG, BMP natively
using (var image = XImage.FromFile("photo.jpg"))
{
    gfx.DrawImage(image, 50, 50, 300, 200);
}

document.Save("with-image.pdf");

Reading and Modifying Existing PDFs

using PdfSharpCore.Pdf;
using PdfSharpCore.Pdf.IO;

// Open existing PDF
var document = PdfReader.Open("existing.pdf", PdfDocumentOpenMode.Modify);

// Add a new page
var page = document.AddPage();
var gfx = XGraphics.FromPdfPage(page);
gfx.DrawString("New page added!", new XFont("Arial", 16), XBrushes.Black, new XPoint(20, 20));

document.Save("modified.pdf");

Handling Broken PDFs with Lazy Reading

using PdfSharpCore.Pdf;
using PdfSharpCore.Pdf.IO;
using PdfSharpCore.Pdf.IO.enums;

// Use Lazy accuracy for non-standard or corrupted PDFs
var document = PdfReader.Open(
    "broken.pdf", 
    PdfDocumentOpenMode.ReadOnly,
    null,
    PdfReadAccuracy.Lazy
);

Console.WriteLine($"Pages: {document.PageCount}");

Checking Digital Signatures

using PdfSharpCore.Pdf;
using PdfSharpCore.Pdf.IO;

var document = PdfReader.Open("signed.pdf");

if (document.IsSigned)
{
    Console.WriteLine("Document is digitally signed");

    // Access signature details (preliminary support)
    foreach (var signature in document.Signatures)
    {
        // Validate signature
        Console.WriteLine($"Signature found: {signature}");
    }
}

Advanced Features

MigraDoc Support

This package also includes MigraDoc (version 1.32), a document generation framework built on top of PdfSharpCore:

using MigraDocCore.DocumentObjectModel;
using MigraDocCore.Rendering;

var document = new Document();
var section = document.AddSection();

section.AddParagraph("Hello MigraDoc!")
    .Format.Font.Size = 20;

var renderer = new PdfDocumentRenderer
{
    Document = document
};
renderer.RenderDocument();
renderer.PdfDocument.Save("migradoc-output.pdf");

Font Support

Font rendering is powered by SixLabors.Fonts, providing excellent cross-platform font support.

Table of Contents

Contributing

We appreciate feedback and contributions to this repo! Feel free to:

  • Report bugs or issues
  • Suggest new features
  • Submit pull requests
  • Improve documentation

License

This software is released under the MIT License. See the LICENSE file for more info.

Mavusi.PdfSharpCore relies on the following projects:


Note: This is a fork of the original PdfSharpCore. If you're looking for the original project, visit https://github.com/ststeiger/PdfSharpCore

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Mavusi.PdfSharpCore:

Package Downloads
Mavusi.HtmlRendererCore.PdfSharp

HtmlRendererCore is a partial port of HtmlRenderer for .NET Core. Supports rendering HTML to PDF using PdfSharp on .NET 8, 9, and 10. Includes bundled Liberation Fonts for Docker and cloud environments - no system fonts required! Lightweight with minimal dependencies - no ImageSharp required.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.2 81 4/16/2026
2.0.1 89 4/16/2026
2.0.0 157 4/15/2026
1.0.0 3,357 8/18/2025

Version 2.0.2: Simplified README documentation for end-users. Native image support for JPEG, PNG, BMP without external dependencies.