PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2010 How to filter strings and send new string to Richtextbox. (PDF conversion was done)-VBForums
Results 1 to 17 of 17

Thread: How to filter strings and send new string to Richtextbox. (PDF conversion was done)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    29

    Post How to filter strings and send new string to Richtextbox. (PDF conversion was done)

    Hello family,

    Okay, How do I filter strings.


    So I have converted a PDF file into String using itextsharp and I have the text displayed into a Richtextbox1.

    However there are too many irrelevant text that I don't need in the Richtextbox.

    Is there a way I can display the text I want based on keywords, the entire length of the test.

    Example of text that is displayed in textrichbox1 after conversation of PDF to text:

    1
    2
    3
    3
    4
    4
    A A
    B B
    SHEET 1 OF 1
    774
    SIZE
    SCALE
    24.000-47.999
    12.000-23.999
    CON BAG
    WIRE
    90in. EX
    Bos00232940
    Bos00320491
    Das1234
    Das3216

    DETAILS
    1 2
    RAGE
    That's displayed in the RichTextbox1. I want to filter the irrelevant text and only display the ones I want based on keywords.

    So the keywords would be "Bos", "Das", "774". and the new text that would be displayed in the richtextbox1 is shown below, instead of the entire text above.

    Bos00232940
    Bos00320491
    Das1234
    Das3216
    774
    How can I do this? Or its not possible with VB?

    PS: The only reason why I have to do it this way is because I can't set an event to doubleclick on the Axacropdf1 activeX control. My goal is to print the selected name base on the name in the Pdf file. all the pdf files are located in an external drive.
    So with this, I can have the name "das1234" in richtextbox, allowing me to set a doubleclick event and send the pdf to the printer for automatic printing.


    Thanks,


    Steve.

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,710

    Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    yea it can be done. I don't know how your text is handled after the pdf conversion, but I'm going to assume you have the text in an array of strings. If the text is all in one string, then you will need to split it up base on the CrLf's in the string.

    So yea, anyway for each of your lines of text, use the String.Contains method to see if the line contains one of your keywords, if so, move that line into a new string. After you are done, show the new string in the textbox.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    29

    Post Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    Quote Originally Posted by kebo View Post
    yea it can be done. I don't know how your text is handled after the pdf conversion, but I'm going to assume you have the text in an array of strings. If the text is all in one string, then you will need to split it up base on the CrLf's in the string.
    The text from the PDF is converted into the string and is displayed exactly how I have it in the first post.

    SCALE
    24.000-47.999
    12.000-23.999
    CON BAG
    WIRE
    90in. EX
    Bos00232940
    So for example the above text would be known as THETEXT.

    Code:
    Imports System
    'since 'THETEXT' is already a string (converted pdf)we don't need to declare it a variable.
     
       Public Shared Sub myfilteredtext()
          Dim s1 = thetext
          Dim s2 As String = "Bos" 
          Dim b As Boolean
          b = s1.Contains(s2)
          RichTextBox1.Text = myfilteredtext
    ' This should print out the new string Bos00232940 into the richtextbox?
        End Sub
    End Class
    Sorry if I don't follow along, Its my own lack of knowledge.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    29

    Post Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    Code:
    Imports iTextSharp.text.pdf
    
    Public Class Form1
        
        Public Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        
        End Sub
        Public Shared Function GetTextFromPDF(ByVal PdfFileName As String) As String
           
            Dim oReader As New iTextSharp.text.pdf.PdfReader(PdfFileName)
    
            Dim sOut = ""
    
            For i = 1 To oReader.NumberOfPages
                Dim its As New iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy
    
                sOut &= iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(oReader, i, its)
            Next
    
            Return sOut
        End Function
    
        Public Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    
        End Sub
    
        Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim pdffilename As String
            pdffilename = TextBox1.Text
            Dim filepath = "c:\temp\" & TextBox1.Text & ".pdf"
            Dim thetext As String
            thetext = GetTextFromPDF(filepath)
          
    'Here I need 'thetext' to filter the string and only send the new strings to the richtextbox.
    
           RichTextBox1.Text = thetext
            
    
    
    End Sub
        Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
    
        End Sub
    
    End Class

  5. #5
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,710

    Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    it's ok, at least you looked at the documentation

    If theText contains everything in the textbox then you first need to split it up....
    vb Code:
    1. dim lines() as string  = System.Text.RegularExpressions.Regex.Split(theText, environment.newline)

    now you have each line of text in an array that your can iterate through
    vb Code:
    1. dim newTextLines as new List(of String)
    2. For each line as string in lines
    3.  
    4. 'check each line again each keyword.
    5.      For each keyWord as string in myKeyWords
    6.        
    7.           'use the contains method here
    8.           if line.Contains(keyWord) Then
    9.                  newTextLines.Add(line)
    10.                  exit for
    11.          endif
    12.      Next
    13. Next
    'now you have all the lines that meet the keyword criteria so put them into the textbox
    vb Code:
    1. RichTextBox1.Text = String.Join(Environment.Newline,newTextLines.Toarray)

    That is all free handed, so there may be some syntax issues.
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    29

    Post Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    Quote Originally Posted by kebo View Post
    it's ok, at least you looked at the documentation

    If theText contains everything in the textbox then you first need to split it up....
    I'm afraid I don't understand, 'thetext' is a string I get from the PDF conversion, this has nothing to do with the textbox, the textbox is there for me to enter the PDF file name, then looks for that file. then convert it into text aka (thetext).

    So I need to extract certain text based on keywords I define.

    I've tried the code you gave me, but with my own lack of knowledge I don't understand how to implement it.

    Code:
     Dim lines() As String = System.Text.RegularExpressions.Regex.Split(thetext, Environment.NewLine)
            Dim newTextLines As New List(Of String)
    
            For Each line As String In lines
    
                For Each Bos As String In thetext
    
                    If line.Contains(Bos) Then
                        newTextLines.Add(line)
                        Exit For
                    End If
                Next
            Next
            RichTextBox1.Text = String.Join(Environment.NewLine, newTextLines.ToArray)

  7. #7
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,710

    Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    I'm afraid I don't understand, 'thetext' is a string I get from the PDF conversion, this has nothing to do with the textbox, the textbox is there for me to enter the PDF file name, then looks for that file. then convert it into text aka (thetext).
    OK my bad What I am saying is that if theText contains all of the text from the pdf, then you need to split it.

    I've tried the code you gave me, but with my own lack of knowledge I don't understand how to implement it.
    Go back to post #4 . See here your code says "'Here I need..."? Insert the code I gave you there. Then put a breakpoint on the first line of code in the button click event handler and run the code. When it breaks, step through the code using F10 and see what is happening. Its the best way to learn.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    29

    Unhappy Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    It doesn't work, or maybe I'm not understanding what exactly is happening. but I still see the entire PDF text and not the extracted text from the string.

    Code:
    Dim thetext As String
            thetext = GetTextFromPDF(filepath)
    
            Dim lines() As String = System.Text.RegularExpressions.Regex.Split(thetext, Environment.NewLine)
    
            Dim newTextLines As New List(Of String)
            For Each line As String In lines
    
                'check each line again each keyword.
                For Each keyWord As String In "Bos"
    
                    'use the contains method here
                    If line.Contains(keyWord) Then
                        newTextLines.Add(line)
                        Exit For
                    End If
                Next
            Next
            RichTextBox1.Text = String.Join(Environment.NewLine, newTextLines.ToArray)
        End Sub

  9. #9
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,710

    Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    'check each line again each keyword.
    For Each keyWord As String In "Bos"
    you are iterating through only one keyword ("Bos"). You need to put all of your keywords in a list or array and iterate through them. More importantly, take a look at how a For:Next statement works with a collection.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    29

    Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    I apologize for the hard time I'm giving you my friend. but I'm still very much a novice when it comes to VB. I will continue to learn it even if I get my program to work like it should.

    As for the list or array, how do I go about doing that exactly? I'm afraid I don't fully understand how it works. If you could please include the "Bos, Das, and 774" into a list or array and please implement that into the code above. I will copy it and see how exactly it works.

    I'm trying very hard here, so far google has not been my best friend :P
    Last edited by kingpain; Dec 28th, 2013 at 06:47 PM.

  11. #11
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,710

    Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    create an new list of string
    dim keywords as new list(of strings)
    keyword.add("Bos")
    keyWord.add("Das")
    keyWord.add("774")

    put that code in directly after you get theText from the pdf.

    I would suggest not to copy the code. Retype it, learn it. It has error in it that you will need to resolve if you simply cut and paste.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    29

    Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    Before you had post that I was already working on something like that

    Public myarraylist As ArrayList
    myarraylist.add("Bos")
    myarraylist.add("Das")
    myarraylist.add("774")

    I will try and work with the codes I have.
    Hopefully it works, so far all I get is the entire PDF converted to text in the richtextbox. not the "Bos00232940"

    I hope this code does not just give me back the text "Bos" in the richtextbox, I want the entire Bos00232940.


    And I love your sig. I'm a quality engineer for a company, and I have a lot of process to fix next year and implement ISO/TS16949.

  13. #13
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,710

    Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    My best suggestion is to lean on the debugging features in visual studio. Don't simply run the app and see what happens. Step through it line by line from the start to finish and you will figure it out.
    GL
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    29

    Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    I tested it, and it still have the entire pdf file as text displayed in the richtextbox1.

    it doesn't extract the keywords and display them.
    Last edited by kingpain; Dec 28th, 2013 at 07:31 PM.

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    29

    Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    Kevin, It doesn't work... any ideas?

  16. #16
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,710

    Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    refer to post #13, understand what is happening in your code and how that is different than what you would expect. Then fix it.If all else fails, you should post relevant code and ask concise questions about things you are not understanding.

    Just about the worst thing you can do however is say it doesn't work and nothing more.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    29

    Re: How to filter strings and send new string to Richtextbox. (PDF conversion was don

    I got it, found another way thanks mate

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width