How to print file without opening?

Asked

Viewed 1,176 times

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 send the file directly to the printer without opening?

  • 1

    In a geal way it is not possible, nor has any advantage to do it. What you can do is use something ready to open and print. You’re not seeing it, but it’s being opened.

  • @bigown, the idea is as follows. The user schedules an appointment for a patient and the system asks: want to print proof? positive case already sends to printer, without needing to open the pdf and click on the print button.

  • This does not change anything, what is the difference to open and then print?

  • Just a request from users (not to have to click twice). If it is not possible to do, I will leave as is

  • Take away the need to double click on your application, you have control over it.

  • I didn’t quite understand, you can explain better?

  • I think I get it now, you’re opening an external PDF reader. I hadn’t really thought about it. It’s not even a C# problem then. There you have to see how to send this reader that is being used to make the impression without user intervention and send this command the way you are doing.

  • i create the file using iTextSharp, and open it using the standard PDF reader through the above code.

  • As I said, it’s not a problem of C#, nor of programming, it’s knowing how to have this reader print automatically. You always put tags that are not of the problems then confuses.

  • @bigown, sorry, I’m still learning.

  • if you can, give an edited one to my post and put a more appropriate tag

  • Actually I think this isn’t even a programming problem, it’s knowing how to manipulate this specific reader, how to send the command you know.

  • Thanks for the help, @Virginio Novic give me the code

Show 8 more comments

1 answer

3


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

Example:

Configure the first 4 lines using local settings on 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 until satisfactory by the tests performed.

Reference: MSDN Forum - Print PDF direct p/ printer

  • 1

    Thank you, that’s just what I need ^^

  • 1

    Well I took a negative vote, has some problem the answer?

  • Strange... I’m not even going to comment on what I’m thinking. Even so, thanks for the help, it was of great value.

  • 1

    @Italorodrigo without problems rapa... tranquility on the ship! relaxes happens.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.