print existing pdf file

[亡魂溺海] 提交于 2019-12-25 01:54:01

问题


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?


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


来源:https://stackoverflow.com/questions/22457307/print-existing-pdf-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!