Results 1 to 4 of 4

Thread: Printing pdf documents from vb 2010

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    4

    Printing pdf documents from vb 2010

    I'm looking for a better way to print pdf documents from a vb 2010 app. I have tried 2 techniques that work, but both have some minor issues that I'd like to address. The 1st technique uses command line arguments as follows:

    Code:
    Dim starterStr As String = "/h /t " & Chr(34) & pdfFileName & Chr(34) & " " & Chr(34) & printerName & Chr(34)
    Dim starter As New ProcessStartInfo("AcroRd32.exe", starterStr)
    Dim print As New Process()
    With print
        .StartInfo = starter
        .Start()
        .Close()
    End With

    But this approach leaves the Acrobat process still running after completion, so users need to manually close the window.

    A 2nd technique that also works is one that sets the Process StartInfo arguments:

    Code:
    Dim print As New Process()
    With print
        .StartInfo.CreateNoWindow = True
        .StartInfo.Verb = "print"
        .StartInfo.FileName = pdfFileName
        .Start()
        .Close()
    End With
    The 2nd technique is more aesthetically pleasing to me, but has the same annoying problem of leaving the Acrobat process running after execution. It also doesn't allow me to set the output printer destination (the above code sends the output to the default printer).

    Any suggestions on:
    1. how to close the Acrobat process
    2. how to set an output printer destination using StartInfo arguments
    3. a better technique that I haven't thought of
    Last edited by dru37; Jan 26th, 2012 at 12:20 PM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Printing pdf documents from vb 2010

    I use ShellExecute rather than anything else...try
    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim PrintPDF As New ProcessStartInfo
    3.         PrintPDF.UseShellExecute = True
    4.         PrintPDF.Verb = "print"
    5.         PrintPDF.WindowStyle = ProcessWindowStyle.Hidden
    6.         PrintPDF.FileName = pdfFileName
    7.         Process.Start(PrintPDF)
    8. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    4

    Re: Printing pdf documents from vb 2010

    Thank you Hack, your suggested approach works also. But it still leaves the Acrobat process running when complete, and it still doesn't allow me to specify an output printer destination different from the default printer.

  4. #4
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    1,965

    Re: Printing pdf documents from vb 2010

    Dont use Adobe reader ... read this thread.

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