简体   繁体   中英

Print PDF file with printdialog vb.net

I'm trying to print a external pdf file with printdialog options but the file is printed with predeterminated printer config

Dim result As DialogResult = PrintDialog1.ShowDialog()
        If (result = DialogResult.OK) Then
            Dim psi As New ProcessStartInfo
            psi.UseShellExecute = True
            psi.Verb = "print"
            psi.WindowStyle = ProcessWindowStyle.Hidden
            psi.Arguments = PrintDialog1.PrinterSettings.PrinterName.ToString()
            psi.FileName = "file.pdf"
            Process.Start(psi)
        End If

You would need to use the "PrintTo" verb rather than the "Print" verb. You would also need to wrap the printer name in quotes if it might have spaces in it. I would suggest making your code a bit more succinct:

Process.Start(New ProcessStartInfo("file.pdf",
                                   $"""{PrintDialog1.PrinterSettings.PrinterName}""") With {.Verb = "printto",
                                                                                            .UseShellExecute = True,
                                                                                            .WindowStyle = ProcessWindowStyle.Hidden})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM