Do you know the best way to do printable reports?
  v7.0 Posted at 21/01/2017 1:05 AM by Tiago Araujo
Making reports on websites printable can be difficult. While there are CSS media and rules to help make pages printable, there are always issues with page breaks, browser quirks and tables.  ​
Figure: Beautiful HTML report
Figure: Bad Example – The printed layout looks nothing like the HTML
Figure: Beautiful PowerBI HTML report
Figure: Bad example – PowerBI print preview scales everything down to fit on a page, you have no real control over how things flow onto multiple pages

The best and most accurate print solution is to use SQL Server Reporting Services (SSRS). You can use SQL Server Reporting Services in MVC even though its only supported by WebForms. 

It's great to include  SQL Server Reporting Services (SSRS) reports in your web application, which can be done with the Microsoft ReportViewer web control...however this only applies to ASP.NET WebForms.

With an iframe and a little bit of code, your reports can also be viewed in your ASP.NET MVC application.

In your MVC project, add a new item of type WebForm.

16-06-2014 10-44-12 AM.png
Figure: Add a new WebForm

Then add the ReportViewer control to the WebForm.

16-06-2014 10-46-58 AM.png
Figure: Add the ReportViewer control

In the View you want to display the report in, add an iframe pointing to your WebForm. 

Tie them together, by getting your report parameters from the MVC page and appending them to the query string of the iframe URL.

(The below example uses JavaScript to execute this part from user input)

16-06-2014 10-50-55 AM.png
Figure: Add an iframe

Now you have your SSRS report in your MVC application.

17-06-2014 8-33-37 AM.png
Figure: The final report in an MVC application
16-06-2014 10-38-51 AM.png
Figure: Export your report with the in-build SSRS functionality

When using Web-API the method above is difficult and time-consuming!


The easy solution is to render the report within the API and return it to the user  as a pdf. For an example of how to implement the functionality, read the following series  of articles on 'Integrating SSRS Web-API and AngularJS' .

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address: