Create a PDF file on button press in browser

2013-04-11

When you use the FastReport .Net together ASP.Net MVC framework you have easy method for creating file in any supported format on button press in HTML form.

Add next code in View:

 @using (Html.BeginForm("GetFile", "Home"))
 {
         <input id="pdf" type="submit" value="Export to PDF" />
 }

GetFile - name of controller handler, Home - name of controller (HomeController.cs for example)

Add name space in controller:

using FastReport.Export.Pdf;

Add method GetFile in controller:

        public FileResult GetFile()
        {
            WebReport webReport = new WebReport();

            // bind data
            System.Data.DataSet dataSet = new System.Data.DataSet();
            dataSet.ReadXml(report_path + "nwind.xml");
            webReport.Report.RegisterData(dataSet, "NorthWind");
           
            // load report
            webReport.ReportFile = this.Server.MapPath("~/App_Data/report.frx");

            // prepare report
            webReport.Report.Prepare();

            // save file in stream
            Stream stream = new MemoryStream();
            webReport.Report.Export(new PDFExport(), stream);
            stream.Position = 0;

            // return stream in browser
            return File(stream, "application/zip", "report.pdf");
        }

 

Example for Excel 2007:

using FastReport.Export.OoXML;
...
webReport.Report.Export(new Excel2007Export(), stream);
...
return File(stream, "application/xlsx", "report.xlsx");


November 20, 2024

Localization and Language Switching in FastReport VCL

FastReport VCL supports 40 languages for interface localization and allows you to change the language on the fly through menus or code, without recompilation.
November 01, 2024

New Features of the FastReport VCL Editor

We are considering new features of the report editor: extension lines, highlighting of intersecting objects, updated report and data trees.
October 30, 2024

Using Styles When Creating Reports in FastReport VCL

The article discusses one of the new features of FastReport VCL — the use of styles and style sheets.
Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2024 Fast Reports Inc.