Upgrade existing projects to PDFsharp 6
Version 6.1.0
In this article
This article describes how to upgrade your existing PDFsharp & MigraDoc Foundation 1.5 projects to PDFsharp 6.
Port an existing project to .NET 6
Starting with PDFsharp 6.1 we retrofit the support of .NET Framework 4.7.2 or higher. If you want to stay with .NET Framework this step is optional.
If you want to upgrade, you can do that manually by editing the project file or use the .NET Upgrade Assistant.
Choose the appropriate NuGet package
Use PDFsharp.6.1.xxxxx.nupkg
or PDFsharp-MigraDc.6.1.xxxxx.nupkg
for the Core build, which does not depend on GDI+ (WinForms) or WPF anymore. The target Frameworks for these packages are net6.0
and netstandard2.0
.
If your project depends on System.Drawing
(GDI+) or System.Windows
(WPF) or if your application targets Windows only, consider using the package with the -GDI
or -WPF
suffix respectively. The target Frameworks for these packages are net6.0-windows
or net472
, thus they can be used under Windows only.
See Upgrade notes in specifications.
Fix breaking changes
There are only very few breaking changes that must be fixed in the code before your project compiles with PDFsharp 6.
- The class XFontStyle is renamed to XFontStyleEx because XFontStyle becomes a slightly different meaning. Change this with a global search and replace in your code editor.
- If you are using MigraDoc, also check breaking changes in MigraDoc.
- If you use the Core build and do not use a specific font resolver, PDFsharp uses the build-in platform font resolver that resolved common fonts like Arial or Times New Roman. For production code you should implement a custom font resolver, see Font resolving.
Use the following temporary hack to make PDFsharp Core work everywhere: Call GlobalFontSettings.FontResolver = new FailsafeFontResolver();
before executing any other code of PDFsharp. As of version 6.1.0 Preview 3, PDFsharp will work under Windows, WSL, and some Linux distributions without setting a font resolver, but this is not recommended for production use.
For production applications, create a FontResolver that matches your requirements if you use the Core build.
Now the part of your code that used PDFsharp or MigraDoc Foundation should work. If you run into problems or other breaking changes, let us know in the forum.