3

I want to do printing in .net core. To do this I am using Process of System.Diagnostics. I tried following code below:

var printJob = new Process
{
    StartInfo = new ProcessStartInfo
    {
        FileName = path,
        UseShellExecute = true,
        Verb = "print",
        CreateNoWindow = true,
        WindowStyle = ProcessWindowStyle.Hidden,
        WorkingDirectory = Path.GetDirectoryName(path)
    }

};

But Verb property is missing in StartInfo in .net core. So then I decided to do printing as follows:

Process.Start("LPR -S ip -P 'Star TSP800L Peeler (TSP828L)' -o 'D:\testpdf.pdf'");

But it gives me

The system cannot find the file specified

whereas the file is present at given location.

Right now I am trying to test with local printer on my windows 10 machine, but what I need is to print to network printer from ubuntu machine.

Can someone tell me, why I am getting file not found error. I have found following link, but it is using StartInfo, which is not helpful to me in this case.

Process.Start in C# The system cannot find the file specified error

Error in Process.Start() -- The system cannot find the file specified

Community
  • 1
  • 1
Purnima Naik
  • 2,393
  • 5
  • 17
  • 25
  • 1
    [lpr command not working from my C# program](http://stackoverflow.com/a/10554282/3060520) – huse.ckr Sep 26 '16 at 13:50
  • 1
    [LPR command to print pcl-file from windows service not working](http://stackoverflow.com/q/11915241/3060520) – huse.ckr Sep 26 '16 at 13:51
  • Now when I am printing to local printer, I am getting print server unreachable or specified printer does not exist error? I am using following command:lpr -S my_machine_ip -P Star TSP800L Peeler (TSP828L) -o l D:\\testpdf.pdf – Purnima Naik Sep 26 '16 at 14:48

1 Answers1

1

Do something like this:

 public static void PrintToASpecificPirnter()
        {
            using (PrintDialog printDialog = new PrintDialog())
            {
                printDialog.AllowSomePages = true;
                printDialog.AllowSelection = true;
                if (printDialog.ShowDialog() == DialogResult.OK)
                {
                    var StartInfo = new ProcessStartInfo
                    {
                        CreateNoWindow = true,
                        UseShellExecute = true,
                        Verb = "printTo",
                        Arguments = "\"" + printDialog.PrinterSettings.PrinterName + "\"",
                        WindowStyle = ProcessWindowStyle.Hidden,
                        FileName = fileName
                    };

                    Process.Start(StartInfo);
                }

            }
    }
cigien
  • 57,834
  • 11
  • 73
  • 112
bigtheo
  • 624
  • 9
  • 16