Sajid Hussain

Sajid Hussain

  • 1.2k
  • 514
  • 100.6k

How to read contend of one page each time of pdf

Dec 4 2015 1:24 AM
i want to convert pdf into text using iTextsharp.dll,i am storing each line into list,my problem is that when i move to second page of pdf,instead of reading just second page line its again start from first end upto second page and so on,i just want that each time i just get content of new page not always start from first.my whole code is as follow.
Hide Expand Copy Code
private void button1_Click(object sender, EventArgs e)  
       {           
  Report_DatabaseEntities ef = new Report_DatabaseEntities();
             OpenFileDialog ofd = new OpenFileDialog(); 
            string filePath;            
            ofd.Filter = "PDF Files(*.pdf)|*.PDF|ALL Files(*.*)|*.*";      
       if (ofd.ShowDialog() == DialogResult.OK)   
          {                 
  filePath = ofd.FileName.ToString(); 
                PdfReader reader = new PdfReader(filePath);  
               string strtext = string.Empty;       
          try             

    {                 
                      List<Report_Class>test1 = new List<Report_Class>();              
       ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy();   
                                      for (int page = 1; page <= reader.NumberOfPages; page++)       
              {                   
      String s = PdfTextExtractor.GetTextFromPage(reader, page, its);     
                    s = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(s)));                         strtext = strtext + s;  
                       string[] test = strtext.Split('\n');        
               foreach(var n in test)             
          {                           test1.Add(new Report_Class() 
                              {
   record=n          
                     }); 
                                           
     }                                           
 }             
        foreach(var sa in test1)          
           {                  
       string test2 = sa.record; 
                        string[] ssize = test2.Split(null);     
                }        
             }           
      catch (Exception ex)      
           {                
     MessageBox.Show(ex.Message);    
             }         
        reader.Close();           

      MessageBox.Show("File Has been UPLOAD");             }         }



Answers (2)