C# 将 pdf 文件发送到打印机 - 打印 pdf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17448465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 09:30:12  来源:igfitidea点击:

send pdf file to a printer - print pdf

c#pdfprinting

提问by Alsan

I'm programming a web application with Visual Studio 2010 (C#). I want to send a PDF (saved in my computer) to a printer when I click a button.

我正在使用 Visual Studio 2010 (C#) 编写 Web 应用程序。我想在单击按钮时将 PDF(保存在我的计算机中)发送到打印机。

To create the PDF I used iTextSharp. I tried this, but it just opens Adobe Reader:

为了创建 PDF,我使用了 iTextSharp。我试过这个,但它只是打开 Adob​​e Reader:

               proc.StartInfo.FileName = @"C:\Archivos de programa\Adobe\Reader10.0\Reader\AcroRd32.exe";
               proc.StartInfo.Arguments = String.Format(@"/p /h {0}", pdfFileName);
               proc.StartInfo.UseShellExecute = false;
               proc.StartInfo.CreateNoWindow = true;

               proc.Start();

Thank you in advance!!!

先感谢您!!!

采纳答案by Johan Hjalmarsson

this has already been asked and answered here: How can I send a file document to the printer and have it print?

这已经在这里被询问和回答: 如何将文件文档发送到打印机并打印?

The code that was used:

使用的代码:

private void SendToPrinter()
    {
        ProcessStartInfo info = new ProcessStartInfo();
        info.Verb = "print";
        info.FileName = @"c:\output.pdf";
        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();
    }

it basicly opens a "hidden" pdf-reader, tells it to print, waits for it to finish then close it down

它基本上打开一个“隐藏的”pdf阅读器,告诉它打印,等待它完成然后关闭它