0

I have an application that writes SSRS reports as a PDF to a file directory and I would like each time a report is added to the folder for it to be printed to a specific network printer. The reports are generated using the SQL SSRS web service.

This folder and application is on a server and I cannot use Adobes silent printing to accomplish this. Does anyone have any advice?

Thanks.

dev53
  • 404
  • 10
  • 26
  • Look up the Win32 Print Spooler API. You'll have to use platform invoke to call these native functions from C#. – RogerN Mar 14 '16 at 18:58

2 Answers2

1

You could try sending your document as raw or you might be able to convert your file to a stream and send it to your printer using TcpClient.

Community
  • 1
  • 1
mark_h
  • 5,233
  • 4
  • 36
  • 52
1

Realized I left this question unanswered and wanted to give a followup in case anyone else encounters this problem. I ended up using the code from the answer found here...

Print a ReportViewer Without Preview

I was able to create the reports using my web service and put them into a report viewer and then simply pass the report and the printer I wanted to print to as parameters to the code above and it handled the printing for me. The only thing I did was extend the functionality to accept a printer name as a parameter and use assign that as the specified printer that I wanted to print to.

Here is some sample code in case anyone wants to see the general flow I used.

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

There is some other logic here and there but that is the basic idea that will get the job done.

Community
  • 1
  • 1
dev53
  • 404
  • 10
  • 26