【问题标题】:Print PDF To Printer Programmatically C#以编程方式将 PDF 打印到打印机 C#
【发布时间】:2016-03-14 18:32:45
【问题描述】:

我有一个将 SSRS 报告以 PDF 格式写入文件目录的应用程序,我希望每次将报告添加到文件夹中以将其打印到特定的网络打印机。这些报告是使用 SQL SSRS Web 服务生成的。

此文件夹和应用程序位于服务器上,我无法使用 Adob​​e 的静默打印来完成此操作。有人有什么建议吗?

谢谢。

【问题讨论】:

  • 查找 Win32 Print Spooler API。您必须使用平台调用从 C# 调用这些本机函数。

标签: c# pdf reporting-services printing


【解决方案1】:

您可以尝试sending your document as raw 或者您可以将文件转换为流和send it to your printer using TcpClient

【讨论】:

    【解决方案2】:

    意识到我没有回答这个问题,并想在其他人遇到这个问题时进行跟进。我最终使用了此处找到的答案中的代码...

    Print a ReportViewer Without Preview

    我能够使用我的 Web 服务创建报告并将它们放入报告查看器中,然后只需将报告和我想要打印的打印机作为参数传递给上面的代码,它就会为我处理打印。我所做的唯一一件事就是扩展功能以接受打印机名称作为参数并将其指定为我想要打印到的指定打印机。

    这是一些示例代码,以防有人想查看我使用的一般流程。

    List<ReportParameter> reportparms = new List<ReportParameter>();
    
    ServerReport rpt = new ServerReport();
    reportparms.Add(new ReportParameter("param1", param1));
    rpt.ReportServerUrl = reportserver;
    rpt.ReportPath = myReportPath;
    rpt.SetParameters(reportparms);
    
    //I created a class "ReportPrintDocument" for the code from the question linked above.
    ReportPrintDocument rdp = new ReportPrintDocument(rpt, myPrinter);
    rdp.PrinterSettings.PrinterName = ps.Printer;
    
    if (p.PrinterSettings.IsValid)
    {
        rdp.Print();
    }
    

    这里和那里还有一些其他的逻辑,但这是完成工作的基本思想。

    【讨论】:

      猜你喜欢
      • 2010-09-14
      • 2012-12-19
      • 2011-07-24
      • 2011-02-22
      • 1970-01-01
      • 1970-01-01
      • 2013-04-29
      • 1970-01-01
      • 2017-12-31
      相关资源
      最近更新 更多