简体   繁体   中英

print existing pdf file

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?

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();
                }
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM