NullReferenceException in ItextSharp



当我尝试解析一个PDF文件时,我在itextsharp 5.0.6库中遇到以下异常

这是该PDF文件的链接https://backup.filesanywhere.com/fs/v.aspx?v=8c726b8f5a6673b56b6d

                try
                {
                    string s = null;
                    MessageBox.Show("Not-Protected");
                    PdfReader read = new PdfReader(openFileDialog1.FileName);
                    //MessageBox.Show(read.NumberOfPages.ToString());
                    for (int i = 1; i <= read.NumberOfPages; i++)
                    {
                        s = PdfTextExtractor.GetTextFromPage(read, i, new SimpleTextExtractionStrategy());
                        MessageBox.Show(s);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
System.NullReferenceException: Object reference not set to an instance of an object.
   at iTextSharp.text.pdf.PdfContentParser.ReadArray()
   at iTextSharp.text.pdf.PdfContentParser.ReadPRObject()
   at iTextSharp.text.pdf.PdfContentParser.Parse(List`1 ls)
   at iTextSharp.text.pdf.parser.PdfContentStreamProcessor.ProcessContent(Byte[] contentBytes, PdfDictionary resources)
   at iTextSharp.text.pdf.parser.PdfReaderContentParser.ProcessContent[E](Int32 pageNumber, E renderListener)
   at iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(PdfReader reader, Int32 pageNumber, ITextExtractionStrategy strategy)

PDF 第一页的内容流在 TJ 运算符的数组操作数内包含一个数组起始括号 '['。这是不允许的,因为 TJ 运算符的数组操作数可能只包含字符串和数字。

此外,该数组操作数中没有匹配的数组结束括号 '

]',因此数组操作数本身的结束括号关闭了这个(非法的)内部数组,并且数组操作数不再有右括号。因此,iText 将所有剩余的内容流解析到数组中,并在内容流结束时运行到异常中。

众所周知,Adobe Reader会忽略某些错误,并尝试在运行中修复其他错误。知道页面内容描述中不允许嵌套数组,它似乎只是忽略了非法的左括号。Adobe Reader的这种行为非常令人讨厌,因为它允许有缺陷的PDF创建软件蓬勃发展。

PS:有问题的台词:

[(&)110($,"#'#"0'#.(1(2'0',#+345467839':'#.(1;<"'0',#;345467839':'#.(1!=.0',#(345467839':'+.(1(2'0',#+7)(5)35(5467834':'+.(1;<"0',#;7)(5)35(5467834)[(&)110($,"#'#"0'#.(1(2'0',#+345467839':'#.(1;<"'0',#;345467839':'#.(1!=.0',#(345467839':'+.(1(2'0',#+7)(5)35(5467834':'+.(1;<"0',#;7)(5)35(5467834)(':'*!>1;<"0',#;385467837)] TJ
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>^

最新更新