ststeiger / PdfSharpCore

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

PdfSharpCore.Drawing.XImage.FromFile Error #401

Open 3400442579 opened 8 months ago

3400442579 commented 8 months ago

System.MissingMethodException: Method not found: 'SixLabors.ImageSharp.Image1<!!0> SixLabors.ImageSharp.Image.Load(System.String, SixLabors.ImageSharp.Formats.IImageFormat ByRef)'. at PdfSharpCore.Utils.ImageSharpImageSource1.FromFileImpl(String path, Nullable1 quality) at MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes.ImageSource.FromFile(String path, Nullable1 quality) at PdfSharpCore.Drawing.XImage..ctor(String path) at PdfSharpCore.Drawing.XImage.FromFile(String path, PdfReadAccuracy accuracy) at PdfSharpCore.Drawing.XImage.FromFile(String path)

            var page = document.AddPage();
            var gfx = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page);
            gfx.DrawImage(PdfSharpCore.Drawing.XImage.FromFile(@"E:\Dev\Copyright\Web\zdoc\1\signature.png"), new PdfSharpCore.Drawing.XPoint(0, 0));
            document.Save(Path.Combine(path, "signature.pdf"));
LewxX commented 8 months ago

I also had this issue, you can fix it by downgrading your SixLabors.ImageSharp version to 2. in you csproj like so: `<PackageReference Include="SixLabors.ImageSharp" Version="2." />` or I guess the following merge request could fix it, if someone would accept it: #400

alexariza95 commented 4 months ago

still not fixed this, I had to patch it myself so I could use the last version of the library. You just need to extend the class ImageSource as he did with ImageSharpImageSource. The bug is in this method that changed in the lasts upgrades of the library: SixLabors.ImageSharp.Image.Load now only accepts ONE parameter instead of two.

` protected override IImageSource FromBinaryImpl(string name, Func<byte[]> imageSource, int? quality = 75) { ArgumentNullException.ThrowIfNull(imageSource);

var source = imageSource();
Image image = Image.Load(source);
return new ImageSharpImageSourceImplementation(name, image, quality.Value, image.Metadata.DecodedImageFormat is 
PngFormat);
}

`

Here´s an example of an override method I extended in my new class.