export to pdf users i have searched with fastreport
I have a crud application on asp.net mvc core and a search form where i can search the name of user i want and i want that name and its data to print on pdf format using fastreport
This discussion has been closed.
Comments
Hello!
To export only the users found in your search form to PDF in ASP.NET Core MVC
Pass the search string `q` (or an already filtered list of users from EF Core / the database) to the controller method and use `Report` + `PDFExport` to a `MemoryStream`:
[HttpGet] public IActionResult ExportUserPdf(string q) { var filtered = _db.Users.Where(u => string.IsNullOrEmpty(q) || u.Name.Contains(q)).ToList(); using var rep = new FastReport.Report(); rep.Load(‘Reports/Users.frx’); rep.RegisterData(filtered, ‘Users’); rep.GetDataSource(‘Users’).Enabled = true; rep.Prepare(); using var ms = new MemoryStream(); using var pdf = new FastReport.Export.Pdf.PDFExport { ShowProgress = false }; rep.Export(pdf, ms); return File(ms.ToArray(), ‘application/pdf’, ‘users.pdf’); }Alternatively, you can register the full dataset and set the filter via a report parameter: rep.SetParameterValue(‘SearchName’, q) + the DataBand.Filter property.