首页 > 解决方案 > iText 7.1.14 'SymbolEncoding' 不是受支持的编码名称

问题描述

我正在使用以下代码在 PowerShell 中使用 iText7 阅读一些 Chase 银行对账单,

$path = .\blabla.pdf
Add-Type -Path "$PSScriptRoot\dll\itext.kernel.dll" #dll loads nicely.
$pdfDoc  = [iText.Kernel.Pdf.PdfDocument]::new([iText.Kernel.Pdf.PdfReader]::new($path))
$text = for ($a = 1; $a -le $pdfdoc.GetNumberOfPages(); $a++) {
    [iText.Kernel.Pdf.Canvas.Parser.PdfTextExtractor]::GetTextFromPage($pdfDoc.GetPage($a))
}

iText7 可以很好地读取大多数语句,但从某些语句中我得到以下错误

ErrorRecord                 : Exception calling "GetTextFromPage" with "1" argument(s): "'SymbolEncoding' is not a supported encoding name. For       
                              information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
                              Parameter name: name"
WasThrownFromThrowStatement : False
Message                     : Exception calling "GetTextFromPage" with "1" argument(s): "'SymbolEncoding' is not a supported encoding name. For       
                              information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
                              Parameter name: name"
Data                        : {System.Management.Automation.Interpreter.InterpretedFrameInfo}
InnerException              : System.ArgumentException: 'SymbolEncoding' is not a supported encoding name. For information on defining a custom       
                              encoding, see the documentation for the Encoding.RegisterProvider method.
                              Parameter name: name
                                 at System.Globalization.EncodingTable.internalGetCodePageFromName(String name)
                                 at System.Globalization.EncodingTable.GetCodePageFromName(String name)
                                 at iText.IO.Util.IanaEncodings.GetEncodingEncoding(String name)
                                 at iText.IO.Util.EncodingUtil.ConvertToBytes(Char[] chars, String encoding)
                                 at iText.IO.Font.PdfEncodings.ConvertToBytes(String text, String encoding)
                                 at iText.IO.Font.FontEncoding.FillNamedEncoding()
                                 at iText.IO.Font.FontEncoding.CreateFontEncoding(String baseEncoding)
                                 at iText.Kernel.Font.PdfType1Font..ctor(PdfDictionary fontDictionary)
                                 at iText.Kernel.Font.PdfFontFactory.CreateFont(PdfDictionary fontDictionary)
                                 at iText.Kernel.Pdf.Canvas.Parser.PdfCanvasProcessor.GetFont(PdfDictionary fontDict)
                                 at iText.Kernel.Pdf.Canvas.Parser.PdfCanvasProcessor.SetTextFontOperator.Invoke(PdfCanvasProcessor processor,        
                              PdfLiteral operator, IList`1 operands)
                                 at iText.Kernel.Pdf.Canvas.Parser.PdfCanvasProcessor.InvokeOperator(PdfLiteral operator, IList`1 operands)
                                 at iText.Kernel.Pdf.Canvas.Parser.PdfCanvasProcessor.ProcessContent(Byte[] contentBytes, PdfResources resources)
                                 at iText.Kernel.Pdf.Canvas.Parser.PdfTextExtractor.GetTextFromPage(PdfPage page, ITextExtractionStrategy strategy,   
                              IDictionary`2 additionalContentOperators)
                                 at CallSite.Target(Closure , CallSite , Type , Object )
TargetSite                  : Void ConvertToMethodInvocationException(System.Exception, System.Type, System.String, Int32,
                              System.Reflection.MemberInfo)
StackTrace                  :    at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type    
                              typeToThrow, String methodName, Int32 numArgs, MemberInfo memberInfo)
                                 at CallSite.Target(Closure , CallSite , Type , Object )
                                 at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
                                 at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
HelpLink                    :
Source                      : System.Management.Automation
HResult                     : -2146233087

我完全失去了。我不是程序员,我的一生都无法弄清楚如何解决这个问题。我什至找不到几乎任何与此错误相关的 iText 相关帖子(一篇帖子)。我可以在 PowerShell 中做些什么来解决这个问题吗?

我希望我能够提供可以重现此错误的 PDF,但我在大通银行对帐单上遇到了此错误,所以......是的。作为参考,我在(07,2015 - 10,2016 和一些 2018 年)的银行对账单上发现了错误。

标签: powershellitext7

解决方案


推荐阅读