2

The following code at least works perfectly printing a pdf file in Windows 7, but is blowing an error in Windows 8:

                Process process = new Process();
            //process.StartInfo.CreateNoWindow = true;
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.StartInfo.FileName = defFile;
            if (rwPrinter.Length > 0)
            {
                process.StartInfo.Verb = "printto";
                process.StartInfo.Arguments = "\"" + rwPrinter + "\"";
            }
            else
            {
                process.StartInfo.Verb = "print";
            }
            process.Start();

Here are some details of the error:

************** Exception Text **************
System.ComponentModel.Win32Exception (0x80004005): 
No application is associated with       the specified file for this operation
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at ECitation.Form1.process_ticket(String jobdo)
at ECitation.Form1.btnPrint_Click(Object sender, EventArgs e)

I know there's an adobe reader for pdf files anyways but am stuck as to what I need to get working on Windows 8 so this error doesn't happen again.

edit, now this is weird in Windows 8: printto is not recognized as an internal or external command

I tried googling this but am shocked no results come up. All I want to do is programmically print my document to a specific printer.

jfalberg
  • 141
  • 4
  • 16

1 Answers1

0

The error message tells you all you need to know. There is nothing defined for the printto verb on the .pdf file extension. You'll need to configure your file associations to remedy that if you want this approach to work.

The way you are attempting to do this is pretty brittle, relying as it does on the vagueries of a third party PDF viewer. If you control all the machines on which the application runs, you can configure the PDF viewer as you like. Otherwise you can expect to deal with a lot of customer support. A more robust solution would be to build the PDF printing capability into your application using one of the many libraries that offer such capabilities.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • It certainly was misleading for me when I clicked on a pdf file and thought it was Adobe when it really was Windows 8's generic PDF viewer that had no file association in reality. Once I installed Adobe reader and used the print command to assume using the default printer it worked. I'll probably need to keep a copy of the old printto.exe file for those that are not defaulted to that printer then. – jfalberg Aug 19 '13 at 20:21
  • There is no printto .exe file. There is a verb, printto, that is associated with the .pdf extension. – David Heffernan Aug 19 '13 at 20:31
  • I have installed AdobeReader and assosiated it with pdf, but this doesn't work. It just throws : "The specified executable is not a valid application for this OS platform." exception – Artem A Oct 30 '15 at 16:20