ststeiger / PdfSharpCore

Port of the PdfSharp library to .NET Core - largely removed GDI+ (only missing GetFontData - which can be replaced with freetype2)
Other
1.06k stars 235 forks source link

Support ImageSharp 3 #343

Open jamesgurung opened 1 year ago

jamesgurung commented 1 year ago

In the latest major release of ImageSharp, there are some breaking API changes. This causes compatibility issues if a project uses ImageSharp 3 alongside PdfSharpCore.

Minimal repro:

Project.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="PdfSharpCore" Version="1.3.47" />
    <PackageReference Include="SixLabors.ImageSharp" Version="3.0.0" />
  </ItemGroup>
</Project>

Program.cs

using PdfSharpCore.Drawing;
var image = XImage.FromFile("test.png");

Error

System.MissingMethodException: 'Method not found: 'SixLabors.ImageSharp.Image`1\<!!0> SixLabors.ImageSharp.Image.Load(System.String, SixLabors.ImageSharp.Formats.IImageFormat ByRef)'.' at PdfSharpCore.Utils.ImageSharpImageSource`1.FromFileImpl(String path, Nullable`1 quality) at MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes.ImageSource.FromFile(String path, Nullable`1 quality) at PdfSharpCore.Drawing.XImage..ctor(String path) at PdfSharpCore.Drawing.XImage.FromFile(String path, PdfReadAccuracy accuracy) at PdfSharpCore.Drawing.XImage.FromFile(String path) at Program.\<Main>$(String[] args) in Program.cs:line 2

jafin commented 1 year ago
  1. ImageSharp 3 changes the license https://github.com/SixLabors/ImageSharp/blob/main/LICENSE Which should fine, as this package is open source and therefore should fall under their Apache 2 part of the split license.

Works in Source or Object form are licensed to You under the Apache License, Version 2.0 if.

  • You are consuming the Work in for use in software licensed under an Open Source or Source Available license.
  1. ImageSharp 3 supports only net6 LTS. This package is netstandard 2.0;net6.0. Therefore it would have to drop the netstandard 2.0 compatibility. There is value in maintaining netStandard2.0 IMHO. @ststeiger being the package owner may have to chime in on that one.

This package could possibly move to ImageSharp 2.1.3 which maintains compatibility with netstandard 2.0. (but may not provide the outcome you desire)

Perhaps, there may be a way to isolate the ImageSharp features into own assembly, and create a plugin approach to have a plugin for both ImageSharp 2 and 3 at runtime.

mapo80 commented 1 year ago

I've created this pull request: https://github.com/ststeiger/PdfSharpCore/pull/353

Use different ImageSharp versions base on .Net version.

jamesgurung commented 1 year ago

Perhaps, there may be a way to isolate the ImageSharp features into own assembly, and create a plugin approach to have a plugin for both ImageSharp 2 and 3 at runtime.

Would this be a possible way forward? So the PdfSharpCore package can be installed alongside PdfSharpCore.ImageSharp2 or PdfSharpCore.ImageSharp3. Then developers can choose which to use.

I understand the concern about licensing, however for lots of smaller projects ImageSharp is still free and it would be great to be able to use the latest version in projects without breaking PdfSharpCore.