iText7迁移PDF合并函数遭遇BouncyCastle依赖错误求助
问题:用iText7实现PDF字节数组合并功能
我已经用iTextSharp实现了从数据库流式读取PDF字节数组并合并的函数,代码如下:
Public Function PDF_Functions_AddPages(PDFByteContent As List(Of Byte())) As Byte() Try Using MS As New System.IO.MemoryStream Using vDoc As New iTextSharp.text.Document() Using vCopy As New PdfSmartCopy(vDoc, MS) vDoc.Open() For Each Row In PDFByteContent Using vReader As New PdfReader(Row) vCopy.AddDocument(vReader) End Using Next vDoc.Close() End Using End Using Return MS.ToArray() End Using Catch ex As Exception EmailError(ex) Return Nothing End Try End Function
但我不知道如何用iText7实现相同的功能。
更新:尝试的iText7代码及报错
我尝试了以下iText7代码:
Function PDF_AddPages(PDFByteContent As List(Of Byte())) As Byte() Try Using MS As New System.IO.MemoryStream Using vWriter As New iText.Kernel.Pdf.PdfWriter(MS) Using vMerged As New iText.Kernel.Pdf.PdfDocument(vWriter) Dim vMerger As New iText.Kernel.Utils.PdfMerger(vMerged) For Each Row In PDFByteContent Using copyFromMS As New MemoryStream(Row) Using vReader As New iText.Kernel.Pdf.PdfReader(copyFromMS) Using copyFromDoc As New iText.Kernel.Pdf.PdfDocument(vReader) vMerger.Merge(copyFromDoc, 1, copyFromDoc.GetNumberOfPages()) End Using End Using End Using Next End Using End Using Return MS.ToArray() End Using Catch ex As Exception EmailError(ex, 2226, PageName) Return Nothing End Try End Function
但这段代码抛出了与BouncyCastle相关的错误:
System.TypeInitializationException: The type initializer for 'iText.Bouncycastleconnector.BouncyCastleFactoryCreator' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) at iText.Bouncycastleconnector.BouncyCastleFactoryCreator..cctor()
……或许我离解决问题更近一步了?
内容的提问来源于stack exchange,提问作者gchq
相关产品推荐
相关产品推荐

