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.
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");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.
We appreciate feedback and contribution to this repo!
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:
- SkiaSharp and SixLabors.Fonts
- SkiaSharp is licensed under the MIT license. SixLabors.Fonts is licensed under Apache 2.0; see https://github.com/SixLabors/Fonts/blob/master/License.txt