IText7 在 .NET 5 上抛出 FileNotFoundException

IText7 Throws FileNotFoundException on .NET 5

IText7 Version : 7.1.14

我们检测到无法在 .NET 5 中使用 IText7 :

private byte[] BuildPDF()
{
   using(var stream = new MemoryStream())
   {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(stream));
        Document doc = new Document(pdfDoc);

        Table table = new Table(UnitValue.CreatePercentArray(8)).UseAllAvailableWidth();

        for (int i = 0; i < 16; i++)
        {
           table.AddCell("hi");
        }

       doc.Add(table);

       doc.Close();
   
       return stream.ToArray();
   }
}

此简单代码适用于 .NET Core 3.1 项目,但不适适用于 .NET 5 项目。

抛出Exception如下:

An unhandled exception occurred while processing the request.
FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.PlatformAbstractions,
Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. 
The system cannot find the file specified.

iText.IO.Util.ResourceUtil.LoadITextResourceAssemblies()

TypeInitializationException: The type initializer for 'iText.IO.Util.ResourceUtil' threw an exception.

iText.IO.Font.Type1Parser.GetMetricsFile()

找不到 .dll,但如何解决这个问题或如何向 IText7 报告错误?

您可以从上面的 link 或从项目解决方案上的管理 Nuget 包手动安装 https://www.nuget.org/packages/Microsoft.DotNet.PlatformAbstractions/ (Microsoft.DotNet.PlatformAbstractions) 包。