Mavusi.PdfSharpCore 2.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Mavusi.PdfSharpCore --version 2.0.1
                    
NuGet\Install-Package Mavusi.PdfSharpCore -Version 2.0.1
                    
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.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mavusi.PdfSharpCore" Version="2.0.1" />
                    
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.1
                    
#r "nuget: Mavusi.PdfSharpCore, 2.0.1"
                    
#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.1
                    
#: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.1
                    
Install as a Cake Addin
#tool nuget:?package=Mavusi.PdfSharpCore&version=2.0.1
                    
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

This package supports .NET 8, .NET 9, and .NET 10 through multi-targeting.

Before Publishing

  1. Update Version Numbers

    Before publishing a new version, update the version in all project files:

    • PdfSharpCore/Moondigo.PdfSharpCore.csproj
    • PdfSharpCore.Charting/PdfSharpCore.Charting.csproj
    • MigraDocCore.DocumentObjectModel/MigraDocCore.DocumentObjectModel.csproj
    • MigraDocCore.Rendering/MigraDocCore.Rendering.csproj

    Update the following properties:

    <Version>1.0.1</Version>
    <AssemblyVersion>1.0.1.0</AssemblyVersion>
    <FileVersion>1.0.1.0</FileVersion>
    

    Note: Follow Semantic Versioning:

    • MAJOR version for incompatible API changes
    • MINOR version for new functionality in a backward compatible manner
    • PATCH version for backward compatible bug fixes
  2. Update Release Notes (optional but recommended)

    Update the <PackageReleaseNotes> property in each project file to describe what's new in this version.

Publishing Steps

  1. Clean and Build in Release Mode

    dotnet clean
    dotnet build -c Release
    
  2. Create NuGet Packages

    Packages are automatically created during build (when GeneratePackageOnBuild is True). Find them in:

    • PdfSharpCore/bin/Release/
    • PdfSharpCore.Charting/bin/Release/
    • MigraDocCore.DocumentObjectModel/bin/Release/
    • MigraDocCore.Rendering/bin/Release/

    Alternatively, manually pack:

    dotnet pack -c Release
    
  3. Publish to NuGet

    Quick Publish (One Command)

    Copy and paste this command to build and publish all packages at once:

    $apiKey = "YOUR_API_KEY_HERE"; dotnet clean; dotnet build -c Release; Get-ChildItem -Path . -Recurse -Filter "*.nupkg" | Where-Object { $_.FullName -like "*\bin\Release\*" } | ForEach-Object { dotnet nuget push $_.FullName --source https://api.nuget.org/v3/index.json --api-key $apiKey --skip-duplicate }
    

    Or publish using wildcards:

    # Navigate to each project's Release folder or use wildcards
    dotnet nuget push "**/*.nupkg" --source https://api.nuget.org/v3/index.json --api-key YOUR_API_KEY_HERE --skip-duplicate
    

    Or publish each package individually:

    dotnet nuget push PdfSharpCore/bin/Release/Mavusi.PdfSharpCore.1.0.1.nupkg -s https://api.nuget.org/v3/index.json -k YOUR_API_KEY_HERE
    

    Note: Get your NuGet API key from https://www.nuget.org/account/apikeys

  4. Verify Publication

    After publishing, verify your package appears at:

Multi-Targeting Support

The NuGet package includes binaries for:

  • net8.0
  • net9.0
  • net10.0

NuGet will automatically select the appropriate target framework based on the consuming project's target framework.

Contributing

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

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

For Maintainers: Publishing to NuGet

This package supports .NET 8, .NET 9, and .NET 10 through multi-targeting.

Before Publishing

  1. Update Version Numbers

    Before publishing a new version, update the version in all project files:

    • PdfSharpCore/Mavusi.PdfSharpCore.csproj
    • PdfSharpCore.Charting/PdfSharpCore.Charting.csproj
    • MigraDocCore.DocumentObjectModel/MigraDocCore.DocumentObjectModel.csproj
    • MigraDocCore.Rendering/MigraDocCore.Rendering.csproj

    Update the following properties:

    <Version>2.0.1</Version>
    <AssemblyVersion>2.0.1.0</AssemblyVersion>
    <FileVersion>2.0.1.0</FileVersion>
    

    Note: Follow Semantic Versioning:

    • MAJOR version for incompatible API changes
    • MINOR version for new functionality in a backward compatible manner
    • PATCH version for backward compatible bug fixes
  2. Update Release Notes (optional but recommended)

    Update the <PackageReleaseNotes> property in each project file to describe what's new in this version.

Publishing Steps

  1. Clean and Build in Release Mode

    dotnet clean
    dotnet build -c Release
    
  2. Create NuGet Packages

    Packages are automatically created during build (when GeneratePackageOnBuild is True). Find them in:

    • PdfSharpCore/bin/Release/
    • PdfSharpCore.Charting/bin/Release/
    • MigraDocCore.DocumentObjectModel/bin/Release/
    • MigraDocCore.Rendering/bin/Release/

    Alternatively, manually pack:

    dotnet pack -c Release
    
  3. Publish to NuGet

    Quick Publish (One Command)

    Copy and paste this command to build and publish all packages at once:

    $apiKey = "YOUR_API_KEY_HERE"; dotnet clean; dotnet build -c Release; Get-ChildItem -Path . -Recurse -Filter "*.nupkg" | Where-Object { $_.FullName -like "*\bin\Release\*" } | ForEach-Object { dotnet nuget push $_.FullName --source https://api.nuget.org/v3/index.json --api-key $apiKey --skip-duplicate }
    

    Or publish using wildcards:

    dotnet nuget push "**/*.nupkg" --source https://api.nuget.org/v3/index.json --api-key YOUR_API_KEY_HERE --skip-duplicate
    

    Or publish each package individually:

    dotnet nuget push PdfSharpCore/bin/Release/Mavusi.PdfSharpCore.2.0.1.nupkg -s https://api.nuget.org/v3/index.json -k YOUR_API_KEY_HERE
    

    Note: Get your NuGet API key from https://www.nuget.org/account/apikeys

  4. Verify Publication

    After publishing, verify your package appears at:

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 98 4/16/2026
2.0.1 102 4/16/2026
2.0.0 192 4/15/2026
1.0.0 3,401 8/18/2025

Version 2.0.1: Updated README documentation with comprehensive examples and clearer feature descriptions. Native image support for JPEG, PNG, BMP without external dependencies.