Send report to network printer in Reporting for Blazor native

1 Answer 356 Views
.NET Core Report Viewer - Blazor
Roman
Top achievements
Rank 1
Iron
Roman asked on 20 Feb 2023, 02:08 PM
Hi

I'm wondering if there is any possibility to print a report using a specific network printer. From the list of commands I've seen that there is a Print command, that does not take any arguments. I've tested this out and this shows the printing dialog from where I can select the printer and then print the report. This is not exactly what I need.

Is there a way to directly send the report to a network printer (it doesn't matter if it was visible in a ReportViewer before or not, I can handle this in my project) without showing the print dialog?

Best Regards,
Roman 

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 23 Feb 2023, 10:18 AM

Hi Roman,

The printing from the browser relies on the PDF extension of the browser. It is actually a PDF export with a particular JavaScript that invokes the printing dialog of the PDF extension. See the Printing Reports article for details.

I think that for security reasons, printing from a browser requires at least one interaction with the user, hence it may not be possible to print directly from a web viewer. You may check the KB article Print a report directly at client-side without displaying it in a Viewer for more information.

Regards,
Todor
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Roman
Top achievements
Rank 1
Iron
commented on 29 Mar 2023, 01:10 PM

Hi Todor,

Sorry for the late response, I had some other projects to focus on. I see the points with the security reasons, this makes absolutely sense. Without direct printing it makes the whole solution not useful for us, since we don't want the user to be prompted with a printing dialog. I checked your links and I have a few questions about it. The "Printing Reports" article writes that the user will be prompted with the printing dialog anyways, right?

And the Print a report directly at client-side without displaying it in a Viewer article is for HTML5 Report Viewers, not for Blazor Native. Does this matter? I don't really get this article, is there a example project that shows this solution?

Best Regards,
Roman

Roman
Top achievements
Rank 1
Iron
commented on 29 Mar 2023, 01:45 PM | edited

Hi Todor,

I sent my message a bit too early. I managed to print it directly on the network printer without a dialog. I made a HTTP request to my server and in there I created a new InstanceReportSource with the parameters for the report. And then I used the ReportProcessor to print it. Works like a charm. Thanks for your hints :)

For everyone that has the same question, here is my server code:

[HttpPost]
public void PrintReport(ReportSourceOptions source)
{
    PrinterSettings settings = new PrinterSettings();
    settings.PrinterName = @"myPrinter";

    var reportPackager = new ReportPackager();
    using (var sourceStream = File.OpenRead("Reports/TestReport.trdp"))
    {
        var report = (Report)reportPackager.UnpackageDocument(sourceStream);
        var reportSource = new InstanceReportSource();
        reportSource.ReportDocument = report;

        foreach (var paramKey in source.Parameters.Keys)
        {
            reportSource.Parameters.Add(paramKey, source.Parameters[paramKey]);
        }

        Telerik.Reporting.Processing.ReportProcessor processor = new Telerik.Reporting.Processing.ReportProcessor();
        processor.PrintReport(reportSource, settings);
    }
}
Best Regards,
Roman
Todor
Telerik team
commented on 03 Apr 2023, 08:33 AM

Hello Roman,

Thank you for the update.

Indeed, the printing with the ReportProcessor happens server-side, where the ReportProcessor instance is created. Note that in this case, you don't use a viewer or a Reporting REST Service.

Based on the code snippet, you use from the viewer only the parameter values, and the report is hard coded to "Reports/TestReport.trdp". If necessary, you may take also the report name/identifier from the ReportSourceOptions.

Tags
.NET Core Report Viewer - Blazor
Asked by
Roman
Top achievements
Rank 1
Iron
Answers by
Todor
Telerik team
Share this question
or