SSW Foursquare

Do you know the best way to do printable reports?

Last updated by TiagoAraujo over 7 years ago.See history

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.

print reports bad 1
Figure: Beautiful HTML report

print reports bad 2
Figure: Bad Example – The printed layout looks nothing like the HTML

print reports bad 3
Figure: Beautiful PowerBI HTML report

print reports bad 4
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
Figure: Add a new WebForm

Then add the ReportViewer control to the WebForm.

16 06 2014 10 46 58 AM
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
Figure: Add an iframe

Now you have your SSRS report in your MVC application.

17 06 2014 8 33 37 AM
Figure: The final report in an MVC application

16 06 2014 10 38 51 AM
Figure: Export your report with the in-build SSRS functionality

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

2015 04 29 10 09 56 compressor

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'.

We open source. Powered by GitHub