How to print file without opening?

2

My system generates a PDF created in iTextSharp and I use the following code to open it:

System.Diagnostics.Process.Start(nomeArquivo);

nomeArquivo is the address of the PDF file.

How do I get the file straight to the printer without opening it?

    
asked by anonymous 22.01.2017 / 23:07

1 answer

3

A way to send direct to printer, but, you have to install Acrobat Reader (or similar) on your computer.

Example :

Configure the first 4 lines using local settings of your computer

string NomedaImpressora = "Microsoft XPS Document Writer";
string CaminhoeNomedoArquivo = @"C:\Temp\Exemplo.pdf";
string CaminhoDoAcrobat = @"C:\Adobe\Acrobat 11.0\Acrobat\Acrobat.exe";
string DiretorioTemp = @"c:\Temp\Pdf";

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = CaminhoDoAcrobat;            
startInfo.Arguments = string.Format("/t \"{0}\" \"{1}\"",
                                       CaminhoeNomedoArquivo,
                                       NomedaImpressora);
startInfo.CreateNoWindow = true;
startInfo.ErrorDialog = false;
startInfo.UseShellExecute = false;
startInfo.WorkingDirectory = DiretorioTemp;

Process process = Process.Start(startInfo);
process.WaitForInputIdle();
process.CloseMainWindow();
process.Close();
process.Dispose();

The process works satisfactorily by tests performed.

Reference: #

23.01.2017 / 00:35