0

I have made a Windows Form application and I want to print an existing PDF document with my default printer.

I have the file, stored in c:\users\marten\document.pdf.

I have searched a long time for some examples, but the only examples I found was printing a text file or printing a string into a document.

Can someone give me a good example or tutorial?

Marten
  • 1,376
  • 5
  • 28
  • 49

1 Answers1

1

This uses the installed pdf reader to print the file against the default printer on the machine.

string path = "" <- your path here.
if (path.EndsWith(".pdf"))
            {
                if (File.Exists(path))
                {
                    ProcessStartInfo info = new ProcessStartInfo();
                    info.Verb = "print";
                    info.FileName = path;
                    info.CreateNoWindow = true;
                    info.WindowStyle = ProcessWindowStyle.Hidden;
                    Process p = new Process();
                    p.StartInfo = info;
                    p.Start();
                    p.WaitForInputIdle();
                    System.Threading.Thread.Sleep(3000);
                    if (false == p.CloseMainWindow())
                        p.Kill();
                }
            }
GrahamHull
  • 325
  • 1
  • 3
  • 12
  • I tried this and I have the following error: There is no application associated with the specified file for this operation (Translated from Dutch ;)) – Marten Mar 17 '14 at 14:47
  • It works! I have installed Adobe Reader. First, I used the Windows 8 PDF viewer, and that didn't work. – Marten Mar 17 '14 at 16:07