4

I am writing an app which performs some tests and produces a number of different reports. These may be any combination of Labels, PDF for end customer, PDF for repair department, XML file etc.

Depending on the report type, I need to send the file to either the file system or to one of a number of different printers (A4, label etc). Ideally there should be no popup windows - just straight to paper.

How can I send a file (PDF, XML) to a printer? I had thought that for XML/Text I could just File.Copy to LPTn but that doesn't seem to work. For PDF I'm guessing that I could call Acrobat with some parameters which cause the PDF to be printed.

The printers I use are mapped to LPTn. Is there a better way to do this and to store the definitions in the app? i.e. Labels go to MyLabelPrinter and A4 PDFs got to MyA4Printer.

Has anyone done this?

Anas
  • 5,622
  • 5
  • 39
  • 71
paul
  • 13,312
  • 23
  • 81
  • 144

2 Answers2

9
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);
Michal Klouda
  • 14,263
  • 7
  • 53
  • 77
2

Take a look at this webpage. You should find the info you are looking at for PDF. For example, it will look like that:

    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);
Community
  • 1
  • 1
TrizZz
  • 1,200
  • 5
  • 15