send pdf file to a printer - print pdf [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-17 15:34:47

问题


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.

To create the PDF I used iTextSharp. I tried this, but it just opens Adobe 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!!!


回答1:


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



来源:https://stackoverflow.com/questions/17448465/send-pdf-file-to-a-printer-print-pdf

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