This is a migrated thread and some comments may be shown as answers.

Automatically print report from Remote Report Engine in Winforms

2 Answers 579 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Hein
Top achievements
Rank 1
Hein asked on 18 Mar 2020, 08:25 PM

I've implemented the Telerik Reporting engine in a remote ASP.NET Core Web API by following this article. The implementation works as expected - I'm able to retrieve my report template, bind it to data & have a WinForms ReportViewer control render it on the client-side application.

I now wish to implement the ability to automatically print the reports without having to display a UI to users. Ideally we want them to click a button in the application (not from a ReportViewer toolbar) & have the report sent immediately to the printer. We will have the necessary settings available programmatically to configure the printer.

I'm aware of the ReportProcessor.PrintReport() method, which will allow me to do this. What I'm having trouble with is how to configure a ReportSource object that will be passed as the first parameter to PrintReport() that will allow it to request the report from my remote report endpoint. When displaying these reports in the ReportViewer control, a connection string is configured for the remote report server, but I can find no similar concept of any of the ReportSource objects. The closest I could get was by using UriReportSource, but I'm unsure what to set the Uri property to.

Any assistance would be greatly appreciated.

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Todor
Telerik team
answered on 23 Mar 2020, 03:28 PM

Hi Hein,

The ReportProcessor is the class where the Reporting engine is defined, and by using the PrintReport method you will have to make sure the logic that utilizes the class is able to access the report definition, for example, the TRDP file. You will need to pass this TRDP file path in a UriReportSource to the printing method. With this printing, the report is actually rendered in an Image format and sent to the printer. With this approach, you don't need the REST Service as the Reporting engine that runs there is not actually used. Neither there is an endpoint of the REST Service Web API  that will provide the report definition.

If you need the REST Service, e.g. to display reports to the clients in a viewer and to have also the described printing functionality, you may use the REST Service Web API to get a ready document, for example in PDF format, and print it in your Win Forms application. Generally, you will have to:

When you have the document locally you may print it with custom logic.

The Report Viewer uses the same API when previewing a document - you may use Fiddler to check the exact requests to and the responses from the service. 

Regards,
Todor
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Hein
Top achievements
Rank 1
answered on 26 Mar 2020, 03:47 AM

Hi Todor,

Thank you for the detailed feedback. From your post pointing out that the Reporting engine is contained in the ReportProcessor, I realized I was attempting to use the templates wrong. After some changes, I got it to work the way I wanted to. My approach was:

  • Created a custom endpoint to return templates as XML (TRDX)
  • Create a XmlReportSource on the client-side
  • Pass this XmlReportSource to either the viewer or ReportProcessor.PrintReport() method, depending on the requirement

This worked like a charm. Thanks for explaining how the various bits come together!

 

 

 

Tags
General Discussions
Asked by
Hein
Top achievements
Rank 1
Answers by
Todor
Telerik team
Hein
Top achievements
Rank 1
Share this question
or