I am trying to print an existing file to PDF programmatically in Visual Basic 2008.
Our current relevant assets are: Visual Studio 2008 Professional Adobe Acrobat Pr
Imports System.Drawing.Printing
Imports System.Reflection
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim pkInstalledPrinters As String
' Find all printers installed
For Each pkInstalledPrinters In _
PrinterSettings.InstalledPrinters
printList.Items.Add(pkInstalledPrinters)
Next pkInstalledPrinters
' Set the combo to the first printer in the list
If printList.Items.Count > 0 Then
printList.SelectedItem = 0
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim pathToExecutable As String = "AcroRd32.exe"
Dim sReport = " " 'pdf file that you want to print
'Dim SPrinter = "HP9F77AW (HP Officejet 7610 series)" 'Name Of printer
Dim SPrinter As String
SPrinter = printList.SelectedItem
'MessageBox.Show(SPrinter)
Dim starter As New ProcessStartInfo(pathToExecutable, "/t """ + sReport + """ """ + SPrinter + """")
Dim Process As New Process()
Process.StartInfo = starter
Process.Start()
Process.WaitForExit(10000)
Process.Kill()
Process.Close()
Catch ex As Exception
MessageBox.Show(ex.Message) 'just in case if something goes wrong then we can suppress the programm and investigate
End Try
End Sub
End Class