指数数组的边界之外,而读使用iTextSharp的一个.pdf [英] Index was outside the bounds of the array while reading a .Pdf using iTextSharp

查看:597
本文介绍了指数数组的边界之外,而读使用iTextSharp的一个.pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用开源工具iTextSharp的阅读这是在C#.NET编码我Asp.Net MVC3应用.pdf文件进出口。

Im using the Open Source Tool iTextSharp to read a .Pdf file in my Asp.Net MVC3 application which is coded in c#.Net.

下面是我的代码

   filePath = Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory,
                    Path.GetFileName(Infile.FileName));
                    if (System.IO.File.Exists(filePath))
                    {
                        System.IO.File.Delete(filePath);
                    }
                    Infile.SaveAs(filePath);
                    var pdfdoc = new iTextSharp.text.Document();
                    PdfReader reader2 = new PdfReader((string)filePath);
                    string strText = string.Empty;

                    for (int page = 1; page <= reader2.NumberOfPages; page++)
                    {
                        iTextSharp.text.pdf.parser.ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
                        PdfReader reader = new PdfReader((string)filePath);
                        String s = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader, page,its);

                        s = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(s)));
                        strText = strText + s;
                        reader.Close();
                    }



即时得到就行了错误

Im getting the Error on the line

  String s = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader, page,its);



错误为指数数组的边界之外。

问候。

The error is Index was outside the bounds of the array.
Regards.

推荐答案

我通过更新我从5.1 iTextSharp的版本为5.2解决了这个问题。

I resolved this issue by updating my version of iTextSharp from 5.1 to 5.2.

这篇关于指数数组的边界之外,而读使用iTextSharp的一个.pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆