以编程方式将PDF打印到打印机C#

时间:2016-03-14 18:32:45

标签: c# pdf reporting-services printing

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

此文件夹和应用程序位于服务器上,我无法使用Adobes静默打印来完成此操作。有没有人有任何建议?

感谢。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

Print a ReportViewer Without Preview

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

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

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();
}

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