微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

IText7 在 .NET 5 上抛出 FileNotFoundException

如何解决IText7 在 .NET 5 上抛出 FileNotFoundException

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报告错误

解决方法

您可以从以上链接或从项目解决方案的 Manage Nuget Packages 手动安装 https://www.nuget.org/packages/Microsoft.DotNet.PlatformAbstractions/ (Microsoft.DotNet.PlatformAbstractions) 数据包。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。