Printing pdf documents from vb 2010-VBForums
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 11:20 AM.

  2. #2
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,334

    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
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  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,593

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.