How to print PDF with Not default printer with code (VB Net)

时间秒杀一切 提交于 2020-01-06 20:23:32

问题


I´m trying to print a pdf file, there is no problem to print it with the default printer but when I want to do it with a secondary printer it still printing with the default one.

This is my code:

 Dim MyProcess As New Process
 MyProcess.StartInfo.CreateNoWindow = False
 MyProcess.StartInfo.Verb = "print"

 'HERE IS WHERE I WANT TO CHANGE THE PRINTER (BUT THIS COMMAND IS IGNORED)
 MyProcess.StartInfo.Arguments = "Canon MG3500 series"

 MyProcess.StartInfo.UseShellExecute = True
 MyProcess.StartInfo.FileName = My.Application.Info.DirectoryPath & "\Copias digitales\Temp.pdf"
 MyProcess.Start()
 MyProcess.WaitForExit(10000)
 MyProcess.CloseMainWindow()
 MyProcess.Close()

How can I make it?

Thank you all.


回答1:


Use Printer Settings.Printername under the Namespace System.Drawing.Printing

then specify the name of your Printer ( "Canon MG3500 series")

The PrinterSettings control is used to configure how a document is printed by specifying the printer.source

This should do it.

note: This also allows you to use your applied settings on your printer (

i.e. Paper size

I use this everytime I need to use two printers

i.e one for the O.R. then another for a document

Here is a good example of using this along with a combobox to choose any printer in the network.




回答2:


I found the solution replacing the bad line with:

Shell(String.Format("rundll32 printui.dll,PrintUIEntry /y /n ""{0}""", "Printer name"))


来源:https://stackoverflow.com/questions/37714760/how-to-print-pdf-with-not-default-printer-with-code-vb-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!