Printing to a pdf printer programmatically

前端 未结 11 1200
慢半拍i
慢半拍i 2021-01-06 15:40

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

11条回答
  •  攒了一身酷
    2021-01-06 16:35

    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
    

提交回复
热议问题