Introduction
If you want to print a PDF document to another printer than the default printer, you need to use some other switches than in the original article.
Background
As I have more than one printer in my network and Windows 10 likes to change the default printer every time I change the properties of a printer, I needed to make sure that the PDF document was printed with one specific printer.
I got tired of PDF documents printed on photo paper.
Using the Code
This is only a code snippet and assumes that there is a variable containing the path to the PDF file.
string pathPdf = "...";
And this is the full code:
ProcessStartInfo infoPrintPdf = new ProcessStartInfo();
infoPrintPdf.FileName = pathPdf;
string printerName = "Samsung M262x 282x Series";
string driverName = "printqueue.inf";
string portName = "SEC30CDA792D770";
infoPrintPdf.FileName = @"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe";
infoPrintPdf.Arguments = string.Format("/t {0} \"{1}\" \"{2}\" \"{3}\"",
pathPdf, printerName, driverName, portName);
infoPrintPdf.CreateNoWindow = true;
infoPrintPdf.UseShellExecute = false;
infoPrintPdf.WindowStyle = ProcessWindowStyle.Hidden;
Process printPdf = new Process();
printPdf.StartInfo = infoPrintPdf;
printPdf.Start();
System.Threading.Thread.Sleep(10000);
if (!printPdf.CloseMainWindow())
printPdf.Kill(); printPdf.WaitForExit();
printPdf.Close();
How to Find the Printer Variables
In the document Acrobat FAQ on page 27, this information can be found:
AcroRd32.exe /t path "printername" "drivername" "portname"
— Initiates Adobe Reader and prints a file, whose path must be fully specified, while suppressing the Print dialog box. The four parameters of the /t
option evaluate to path
, printername
, drivername
, and portname
(all string
s).
printername
— The name of your printer. drivername
— Your printer driver’s name, as it appears in your printer’s properties. portname
— The printer’s port. portname
cannot contain any "/
" characters; if it does, output is routed to the default port for that printer.
The steps below might be a bit simplistic for some, but maybe not for everyone.
Note: I am using Windows 10, the exact steps might differ on other versions of Windows.
1. Open the Control Panel and select View devices and printers
Right-click on the wanted printer to show the context menu:
1.1. To start with, select Printer Properties
On the General tab, you can find the printer name.
1.2. Select the Ports tab and then click on Configure Port
Now you have the port name.
1.3. You can now close the dialogs.
2. Driver Name
The last information to be found is the driver name. On Windows 10, I found it to be a bit tricky and it is very possible there is a much easier way. Right-click on the printer again, but this time select Properties at the very bottom.
2.1 In the dialog that opens, select the tab Hardware
2.2 Click the button Properties to show the next dialog and select the tab Details
2.3 Select the property Inf Name in the combo box, and voilà; there is the last piece of information.
The value is the printer driver.
History