How to programmatically print various types of files

I am writing an application that performs some tests and creates several different reports. This can be any combination of shortcuts, PDF for the end user, PDF for the repair department, XML file, etc.

Depending on the type of report, I need to send the file to the file system or to one of several printers (A4, shortcut, etc.). Ideally, there should be no pop-ups - right on paper.

How to send a file (PDF, XML) to a printer? I thought for XML / Text I can just File.Copy for LPTn, but this does not seem to work. For PDF, I assume that I could name Acrobat with some options that cause PDF printing.

The printers I use are mapped to LPTn. Is there a better way to do this and save the definitions in the application? The shortcuts go to the MyLabelPrinter and A4 files received in MyA4Printer.

Has anyone done this?

+4
source share
2 answers
ProcessStartInfo info = new ProcessStartInfo("[path to your file]"); info.Verb = "PrintTo"; info.Arguments = "\"[printer name]\""; info.CreateNoWindow = true; info.WindowStyle = ProcessWindowStyle.Hidden; Process.Start(info); 
+8
source

Take a look at this web page . You must find the information you are looking for for PDF. For example, it would look like this:

  ProcessStartInfo infoOnProcess = new ProcessStartInfo("C:/example.pdf"); info.Verb = "PrintTo"; //Put a if there, if you want to change printer depending to file extension info.Arguments = "\"HP-example-Printer\""; info.CreateNoWindow = true; info.WindowStyle = ProcessWindowStyle.Hidden; Process.Start(infoOnProcess); 
+2
source

All Articles