Problem with PdfTextExtractor in itext!

白昼怎懂夜的黑 提交于 2019-12-06 05:20:33

SimpleTextExtractionStrategy doesn't let you reset it unfortunately, so you must move your "new SimpleTextExtractionStrategy()" inside the loop instead of reusing the same object.

krazy

There is another potential problem in the statement which controls your loop:

for (int i = 1; i < pagen; i++)

If pagen = 1, the loop is not executed at all. It should read:

for (int i = 1; i <= pagen; i++)
ShravankumarKumar
public string ReadPdfFile(object Filename,DataTable ReadLibray)
    {
     PdfReader reader2 = new PdfReader((string)Filename);
     string strText = string.Empty;

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

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

This Code is very HelpFull to read PDf using itext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!