【问题标题】:print existing pdf file打印现有的pdf文件
【发布时间】:2014-03-17 14:41:46
【问题描述】:

我创建了一个 Windows 窗体应用程序,我想用我的默认打印机打印现有的 PDF 文档。

我有文件,存储在 c:\users\marten\document.pdf 中。

我已经搜索了很长时间的一些示例,但我找到的唯一示例是打印文本文件或将字符串打印到文档中。

谁能给我一个很好的例子或教程?

【问题讨论】:

    标签: c# pdf printing


    【解决方案1】:

    这将使用已安装的 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();
                    }
                }
    

    【讨论】:

    • 我试过这个,我有以下错误:没有与此操作的指定文件关联的应用程序(翻译自荷兰语;))
    • 有效!我已经安装了 Adob​​e Reader。首先,我使用的是 Windows 8 PDF 查看器,但它不起作用。
    猜你喜欢
    • 1970-01-01
    • 2016-01-10
    • 2011-05-10
    • 1970-01-01
    • 2010-09-21
    • 2012-01-23
    • 2016-05-21
    • 2012-01-02
    相关资源
    最近更新 更多