[英]print existing pdf file
I have made a Windows Form application and I want to print an existing PDF document with my default printer. 我已经制作了Windows窗体应用程序,并且希望使用默认打印机打印现有的PDF文档。
I have the file, stored in c:\\users\\marten\\document.pdf. 我有文件,存储在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. 这将使用已安装的pdf阅读器在计算机上的默认打印机上打印文件。
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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.