logo
small logo
  • Products
  • Buy
  • Support
  • Articles
  • Customer panel Support
    • en
    • pt
    • es
    • de
    • pl
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • Fast sending to print reports in MVC
  • Interactive web report with drill down lists

    August 15, 2017

    In this article we look at how to create interactive reports with drop-down groups. We

    read more
  • How to use FR Core Web Report in Single Page Application Angular 7

    April 29, 2019

    The concept of one-page apps is finding an increasing number of supporters. One of the

    read more
  • How to use WebReport with ASP .NET Web Core application

    January 17, 2018

    Recently FastReport introduced a new library under the .NET - FastReport Core platform. This is

    read more
  • How to use FastCube .NET in the SPA application Knockout.js

    July 21, 2021

    To output the data cube, we will create a SPA application by means of Knockout.js

    read more
  • How to create a report from web application code

    February 16, 2022

    Sometimes creating a report can turn into to be a real headache. For example, when

    read more

Fast sending to print reports in MVC

August 13, 2017

For harmony of Web report with the stylistics of the web page, many people are disable WebReport object toolbar. Thus the user is deprived of options to export and print reports. But if you still want to allow the user to print a report from a browser, you can create a special button to print. By clicking on it, the user will receive the print dialog box.

Now I'll show how to invoke the print dialog in MVC web project.

To start, add a button in the view. I placed it on the home page of my demo web application. Find the Index.html file in the Solution Explorer:

 

Add the button to the desired location:

1
2
3
4
 @using (Html.BeginForm("Print", "Home"))
 {
 <input id="print" type="submit" value="Print" />
 }

 Here Print - name of the handler in the controller. And Home - name of the controller.

Go to the Controllers folder. HomeController.cs file:

 

Add the method to the class code:

1
2
3
4
5
6
7
8
9
10
public void Print()
 {
 WebReport webReport = new WebReport();
 System.Data.DataSet dataSet = new System.Data.DataSet();
 dataSet.ReadXml("C://Program Files (x86)//FastReports//FastReport.Net//Demos//Reports//nwind.xml");
 webReport.Report.RegisterData(dataSet, "NorthWind");
 webReport.Report.Load("C://Program Files (x86)//FastReports//FastReport.Net//Demos//Reports//Simple List.frx");
 webReport.EmbedPictures = true;
 webReport.PrintHtml();
 }

 As you can see a method called Print, as in the button that we added. Let's take a closer look at the code.

In the first line, we created an instance of an object WebReport. Then, we created a DataSet to work with the data. DataSet can work with xml database. Actually in the third line, I specify the path to the database. Using the method RegisterData we register the data source in the report object. Then, load the report template into the report object. It is located in the same folder as the database. EmbedPictures property allows you to embed images in html log file. Finally, the last line starts the printing of the report in the browser.

If you want to save the report in PDF format, then change the last line to:

1
webReport.PrintPdf();

 In this case, you can use options to format pdf file. For example:

1
webReport.PdfPrintOptimized = true;

 This option gives the best image quality for printing.

Now you need to add the handler in the Web.config:

 

 

1
2
3
 <handlers>
 <add name="FastReportHandler" path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport"/>
 </handlers>

 Now run the application. Here is the button on the Web page:

 

Сlick on it. And we get the page with the report and the print dialog:

 

Here is the saving in PDF:

 

Thus it is possible to call the print dialog using the user's button instead of WebReport object toolbar. This can be useful when you embed report controls in web page design.

In this example, we have not added any web report object on the web page. The report is based on a separate page, just before printing. This is useful when there is no need to display the report on a Web page.

about product download buy
avatar
Dmitriy Fedyashov
Technical Writer
Fast Reports Team: Dmitriy Fedyashov - Technical Writer at Fast Reports
.NET FastReport ASP.NET MVC WebReport

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Buy
  • Download
  • Documentation
  • Testimonials
  • How to uninstall
  • Ticket system
  • FAQ
  • Tutorial Video
  • Forum
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Contact us

© 1998-2022 by Fast Reports Inc.

  • Privacy Policy