logo
small logo
  • Products
  • Buy
  • Support
  • About
  • Customer panel Support
    • en
    • de
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • Create a PDF file on button press in browser
  • The Event of ExportParameters in WebReport.Report

    October 5, 2020

    In FastReport 2020.1 we have added the ability to change export parameters. To do this,

    read more
  • MS Word format vs. Open Document Text. Which is better?

    October 19, 2020

    Speaking of text editors, we immediately present coryphaeus as Microsoft Word, which for many years

    read more
  • Want to generate tables for a user - Excel or OpenOffice Calc?

    October 8, 2020

    Tables. For centuries, they have been used to present similar data for record-keeping, counting amounts,

    read more
  • PDF viewing settings when exporting from FastReport.NET

    August 11, 2017

    Title of the article partly reveals subject. I would like to consider configuration a viewer

    read more
  • Instant report from RTF

    October 20, 2021

    Few people know that FastReport .NET report generator allows you to quickly convert an

    read more

Create a PDF file on button press in browser

April 11, 2013

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");


about product buy
avatar
Aleksandr Fediashov
Team lead
Fast Reports Team: Aleksandr Fediashov - Team Lead at Fast Reports
.NET Export FastReport MVC

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
  • FAQ
  • Tutorial Video
  • Forum
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Extended licensing
  • Contact us

© 1998-2023 by Fast Reports Inc.

  • Privacy Policy