Click here to Skip to main content
15,896,727 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
As i develop one simple application in wpf.PDF extraction to text,As i need at the time of extraction apllication shows the status bar which page is loaded in current textviewer.but i couldnot please help me.

XAML code:
XML
<grid>
    <stackpanel orientation="Vertical" verticalalignment="Top" horizontalalignment="Left">
        <stackpanel orientation="Horizontal" verticalalignment="Top" horizontalalignment="Left" margin="10,10,0,0">
            <Button Name="btnBrowse" Width="60" Height="30" Content="Browse" Click="btnBrowse_Click"/>
            <textbox name="txtPath" width="400" height="30" margin="10,0,0,0" />
        </stackpanel>
        <stackpanel orientation="Vertical" horizontalalignment="Stretch">
            <textbox name="txtViewer" width="400" height="300" horizontalalignment="Center" margin="80,10,10,10" acceptsreturn="True" selectionchanged="txtViewer_SelectionChanged" />
            <Button Name="btnExtract" Width="60" Height="30" Content="Extract" Click="btnExtract_Click" />
            <statusbar name="stsbar" height=" 30" removed="white">
                <textblock name="lblCursorPosition" />
            </statusbar>
            </stackpanel>
    </stackpanel>
</grid>

C# code
C#
namespace TestProject
{
   
        public void PdfOcr()
        {
            try
            {
                PDFDoc doc = PDFDoc.Open(m_pdfpath);
                string img = string.Empty;
                List<pagedetail> pages = new List<pagedetail>();
                int pgcount  = doc.PageCount;
                int charcount = 0;
                int wordcount = 0;
                int paracount = 0;
                int linecount = 0;
                string msg = string.Empty;
                for (int i = 1; i &lt;=pgcount; i++)
                {
                    img = doc.GetPageImage(i);
                    var hocr = OcrController.CreateHOCR(OcrMode.Tesseract, "eng", img);
                    hDocument d = new hDocument();
                    d.AddFile(hocr);
                    PageDetail pg = new PageDetail();
                    pg.Pageno = i;
                    foreach (var page in d.Pages)
                    {
                        foreach (var para in page.Paragraphs)
                        {
                            pg.ParaCount++;
                            pg.Text = page.Text;
                            foreach (var line in para.Lines)
                            {
                                pg.LineCount++;
                                foreach (var words in line.Words)
                                {
                                    pg.WordCount++;
                                    pg.CharCount = pg.CharCount + words.Text.Length;
                                }
                            }
                        }
                    }
                    msg ="Pages:" +pg.Pageno + "Line : " + pg.LineCount + "|Para:"+pg.ParaCount + "|Word : " + pg.WordCount + "|Char : " + pg.CharCount + Environment.NewLine;
                    txtViewer.Text += pg.Text;
                    txtViewer.Text += msg;
                    charcount += pg.CharCount;
                    wordcount += pg.WordCount;
                    linecount += pg.LineCount;
                    paracount += pg.ParaCount;
                    pages.Add(pg);
                }
                msg = "TotalPageno:" + pgcount + Environment.NewLine;
                txtViewer.Text += msg;
                msg = "TotalCharacters : " + (wordcount + charcount) +  Environment.NewLine;
                txtViewer.Text += msg;
                MessageBox.Show("Sucessfully done...");
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void btnExtract_Click(object sender, RoutedEventArgs e)
        {

            try
            {
              this.PdfOcr();
            }
            catch (Exception )
            {
              throw;
            }

        }

         private void txtViewer_SelectionChanged(object sender, RoutedEventArgs e)
        {
            
           int row = txtViewer.GetLineIndexFromCharacterIndex(txtViewer.CaretIndex);
           int col = txtViewer.CaretIndex - txtViewer.GetCharacterIndexFromLineIndex(row);
          lblCursorPosition.Text = "line" + (row + 1) + ",char" + (col + 1);
        }
    }
}
Posted
Updated 6-Jan-16 20:44pm
v2
Comments
Maciej Los 7-Jan-16 4:04am    
Does your problem is that, that the status bar is not being updated? If yes, you have to create method to invoke StatusBar.
Please, see: http://elegantcode.com/2009/07/03/wpf-multithreading-using-the-backgroundworker-and-reporting-the-progress-to-the-ui/[^]
Member 11939306 8-Jan-16 8:07am    
As i need source code for when textbox text contents loaded at the the time status bar shown page numbers in wpf
Maciej Los 8-Jan-16 15:53pm    
Follow the link i provided.

1 solution

Hi use the following code,
C#
Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,
     (Action)(() =>
     {
         txtViewer.Text += msg;
     }));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900