Results 1 to 4 of 4

Thread: How to split string and shellexecute print a PDF from conversion to string. PHEW!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    29

    Post How to split string and shellexecute print a PDF from conversion to string. PHEW!

    Hello Family,
    I know my title doesn't make sense, but I don't know who else to word this.
    This is going to be a long one, but easy fix.

    So i've manage to convert a pdf to string, then able to print an external pdf simply by putting the name of the file in a textbox.

    I've also figured how to extract certain text from the pdf string, now the certain text are also files located in an external location (I use c:\temp\ for testing).

    Which leaves me with one problem, the text I extract, I use shellexecute to print, works fine if its one string. however, If the file name I extract is more than one it will count it as a single string, thus adding the location and .pdf to that one string. instead of the two or more strings. which will do something like this:
    c:\temp\bda00207bda00208.pdf

    As you can see, it will send that to the printer. I want to send one at a time to the printer. like this:

    c:\temp\bda00207.pdf
    c:\temp\bda00208.pdf

    I've tried using an Arraylist and various methods. but my own lack of knowledge, I cannot figure it out.

    I'm thinking a "for loop" will help me out. any ideas?
    Below is my code.


    Code:
     Dim pdffilename As String = Nothing
            pdffilename = RawTextbox.Text
            Dim filepath = "c:\temp\" & RawTextbox.Text & ".pdf"
            Dim thetext As String
            thetext = GetTextFromPDF(filepath)        ' converts pdf to text from a function I didnt show.
    
            Dim re As New Regex("[\t ](?<w>((asm)|(asy)|(717)|(ssm)|(715)|(818))[a-z0-9]*)[\t ]", RegexOptions.ExplicitCapture Or RegexOptions.IgnoreCase Or RegexOptions.Compiled)               ' This filters out and extract certain keywords from the PDF
           
            Dim Lines() As String = {thetext}
            Dim words As New List(Of String)
            For Each s As String In Lines
                Dim mc As MatchCollection = re.Matches(s)
                For Each m As Match In mc
                    words.Add(m.Groups("w").Value)
                Next
                RawRich4.Text = String.Join(Environment.NewLine, words.ToArray)
            Next
            'This is where I need help with the code. how to have "words" putout  "c:\temp\" & RawRich4.Text & ".pdf" with each keyword name
    
            Dim rawtoprint As String = String.Join(Environment.NewLine, words.ToArray)
            Dim defname As String = Nothing
            defname = RawRich4.Text
            rawtoprint = "c:\temp\" & RawRich4.Text & ".pdf"
    
            Dim psi As New System.Diagnostics.ProcessStartInfo()
            psi.UseShellExecute = True
            psi.Verb = "print"
            psi.WindowStyle = ProcessWindowStyle.Hidden
            psi.Arguments = PrintDialog1.PrinterSettings.PrinterName.ToString()
            psi.FileName = (rawtoprint) ' this is where the error occurs it doesn't  send both files separately to the printer, it tries to send it as one name
            MessageBox.Show(rawtoprint) ' This is just to test the output, this will be removed. 
            'Process.Start(psi)
    
        End Sub
    Last edited by kingpain; Jan 2nd, 2014 at 06:12 AM.

  2. #2
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    Re: How to split string and shellexecute print a PDF from conversion to string. PHEW!

    Hi,

    A TextBox has a Lines property that can be iterated through. Have a look here:-

    TextBoxBase.Lines Property

    Hope that helps.

    Cheers,

    Ian

    BTW, I would recommend using descriptive names for your variables. It will help you to read and understand your code easier in the future.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    29

    Re: How to split string and shellexecute print a PDF from conversion to string. PHEW!

    Thanks for your answer, I looked at it, and it doesn't seem like it would help me with my problem. I don't know if i explained myself properly. but I will answer any questions and try everything.

  4. #4
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    Re: How to split string and shellexecute print a PDF from conversion to string. PHEW!

    Hi,

    I may have misunderstood your question but, using your own code, you create the contents of a TextBox with something similar to:-

    vb.net Code:
    1. Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    2.   Dim words() As String = {"ASM00200207", "ASM00200208"} 'you get this with regex - this is just an example
    3.   RawRich4.Text = String.Join(Environment.NewLine, words.ToArray)
    4. End Sub

    You can then get each individual line of text by saying:-

    vb.net Code:
    1. Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
    2.   For Each pdfFileName As String In RawRich4.Lines
    3.     MsgBox(String.Format("c:\temp\{0}.pdf", pdfFileName))
    4.   Next
    5. End Sub

    Hope that helps.

    Cheers,

    Ian

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
  •  



Click Here to Expand Forum to Full Width