Results 1 to 4 of 4

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

Threaded View

  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.

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