cyanfish / naps2

Scan documents to PDF and more, as simply as possible.
https://www.naps2.com
Other
2.74k stars 321 forks source link

[SDK] PDFSharpCore dependency #371

Open nataz77 opened 5 months ago

nataz77 commented 5 months ago

Describe the bug When trying to export a pdf, using NAPS2.Sdk and having installed PDFSharpCore 1.3.63 as a dependency on the same project, calling

await pdfExporter.Export(outputPath, images, ocrParams: null);

throws TypeLoadException: Could not load type 'PdfSharpCore.Drawing.IImageSource' from assembly 'PdfSharpCore, Version=1.3.63.0, Culture=neutral, PublicKeyToken=null'.

To Reproduce Install both NAPS2.Sdk and PDFSharpCore:

...
        <PackageReference Include="NAPS2.Images.Gdi" Version="1.0.1" />
        <PackageReference Include="NAPS2.Pdfium.Binaries" Version="1.1.0" />
        <PackageReference Include="NAPS2.Sdk" Version="1.0.0" />
        <PackageReference Include="NAPS2.Tesseract.Binaries" Version="1.2.0" />
        <PackageReference Include="PdfSharpCore" Version="1.3.63" />
...

and try to import and export a PDF file:

        PdfImporter pdfImporter = new(scanningContext);
        List<ProcessedImage> images = [];
        await foreach (ProcessedImage image in pdfImporter.Import(pdfPath))
        {
            images.Add(image.WithTransform(new RotationTransform(180), true).Clone());
        }

        PdfExporter pdfExporter = new(scanningContext);
       await pdfExporter.Export(outputPath, images, ocrParams: null);

Expected behavior The pdf file should export correctly.

Desktop (please complete the following information):

Additional context Removing the PDFSharpCore dependency or referencing directly the version 1.0.0 works, image but also induces memory leaks when exporting documents with 1000+ pages and in other parts of my code.

800903 commented 5 months ago

may be some dlls need add your project.