Skip to content

Port of the PdfSharp library to .NET Core - largely removed GDI+ (only missing GetFontData - which can be replaced with freetype2)

License

Notifications You must be signed in to change notification settings

mapo80/PdfSharpCore

 
 

Repository files navigation

PdfSharpCore

NuGet Version CI codecov.io

PdfSharpCore is a partial port of PdfSharp.Xamarin for .NET Standard. Additionally MigraDoc has been ported as well (from version 1.32). Image support has been implemented with SkiaSharp and Fonts support with SixLabors.Fonts.

Table of Contents

Example

The following code snippet creates a simple PDF-file with the text 'Hello World!'. The code is written for a .NET 6 console app with top level statements.

using PdfSharpCore.Drawing;
using PdfSharpCore.Fonts;
using PdfSharpCore.Pdf;
using PdfSharpCore.Utils;

GlobalFontSettings.FontResolver = new FontResolver();

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

var gfx = XGraphics.FromPdfPage(page);
var font = new XFont("Arial", 20, XFontStyle.Bold);

var textColor = XBrushes.Black;
var layout = new XRect(20, 20, page.Width, page.Height);
var format = XStringFormats.Center;

gfx.DrawString("Hello World!", font, textColor, layout, format);

document.Save("helloworld.pdf");

SkiaSharp Migration

Earlier releases of PdfSharpCore relied on ImageSharp for raster image decoding and simple pixel manipulation before the data was embedded into a PDF. ImageSharp handled tasks such as loading PNG and JPEG files, converting them into bitmap structures, and preserving transparency information so that the drawing engine could consume them.

The project now performs all image processing with SkiaSharp. The SKBitmap based implementation replaces the old ImageSharp pipelines while offering equivalent functionality and better cross-platform behavior. A key motivation for the migration was licensing: ImageSharp is distributed under the Six Labors Split License, which may require commercial licensing in some scenarios, whereas SkiaSharp is MIT licensed and therefore more permissive for open source and commercial use. Comprehensive tests ensure that SkiaSharp matches the previous behavior and provides a solid foundation for future development.

Contributing

We appreciate feedback and contribution to this repo!

License

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

PdfSharpCore relies on the following projects, that are not under the MIT license:

About

Port of the PdfSharp library to .NET Core - largely removed GDI+ (only missing GetFontData - which can be replaced with freetype2)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 96.2%
  • Smalltalk 3.8%